You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by hl...@apache.org on 2010/05/25 19:41:08 UTC

svn commit: r948127 - /tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentClassTransformerImpl.java

Author: hlship
Date: Tue May 25 17:41:08 2010
New Revision: 948127

URL: http://svn.apache.org/viewvc?rev=948127&view=rev
Log:
TAP5-1165: Use OperationTracker to identify component class being transformed

Modified:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentClassTransformerImpl.java

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentClassTransformerImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentClassTransformerImpl.java?rev=948127&r1=948126&r2=948127&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentClassTransformerImpl.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentClassTransformerImpl.java Tue May 25 17:41:08 2010
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007, 2008 The Apache Software Foundation
+// Copyright 2006, 2007, 2008, 2010 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -25,6 +25,7 @@ import org.apache.tapestry5.TapestryMark
 import org.apache.tapestry5.internal.InternalConstants;
 import org.apache.tapestry5.internal.model.MutableComponentModelImpl;
 import org.apache.tapestry5.ioc.LoggerSource;
+import org.apache.tapestry5.ioc.OperationTracker;
 import org.apache.tapestry5.ioc.Resource;
 import org.apache.tapestry5.ioc.annotations.Primary;
 import org.apache.tapestry5.ioc.internal.services.CtClassSource;
@@ -61,6 +62,8 @@ public class ComponentClassTransformerIm
 
     private final ComponentClassCache componentClassCache;
 
+    private final OperationTracker tracker;
+
     private final String[] SUBPACKAGES =
     { "." + InternalConstants.PAGES_SUBPACKAGE + ".", "." + InternalConstants.COMPONENTS_SUBPACKAGE + ".",
             "." + InternalConstants.MIXINS_SUBPACKAGE + ".", "." + InternalConstants.BASE_SUBPACKAGE + "." };
@@ -82,13 +85,16 @@ public class ComponentClassTransformerIm
     @ComponentLayer
     CtClassSource classSource,
 
-    ComponentClassCache componentClassCache)
+    ComponentClassCache componentClassCache,
+
+    OperationTracker tracker)
     {
         this.workerChain = workerChain;
         this.loggerSource = loggerSource;
         this.classFactory = classFactory;
         this.componentClassCache = componentClassCache;
         this.classSource = classSource;
+        this.tracker = tracker;
     }
 
     /**
@@ -100,100 +106,107 @@ public class ComponentClassTransformerIm
         nameToComponentModel.clear();
     }
 
-    public void transformComponentClass(CtClass ctClass, ClassLoader classLoader)
+    public void transformComponentClass(final CtClass ctClass, final ClassLoader classLoader)
     {
-        String parentClassname;
+        tracker.run("Transforming component class " + ctClass.getName(), new Runnable()
+        {
+            public void run()
+            {
+                String parentClassname;
 
-        // Component classes must be public
+                // Component classes must be public
 
-        if (!Modifier.isPublic(ctClass.getModifiers()))
-            return;
+                if (!Modifier.isPublic(ctClass.getModifiers()))
+                    return;
 
-        try
-        {
-            // And have a public constructor.
+                try
+                {
+                    // And have a public constructor.
 
-            CtConstructor ctor = ctClass.getConstructor("()V");
+                    CtConstructor ctor = ctClass.getConstructor("()V");
 
-            if (!Modifier.isPublic(ctor.getModifiers()))
-                return;
-        }
-        catch (NotFoundException ex)
-        {
-            return;
-        }
+                    if (!Modifier.isPublic(ctor.getModifiers()))
+                        return;
+                }
+                catch (NotFoundException ex)
+                {
+                    return;
+                }
 
-        // Is it an inner class (does the class name contain a '$')?
-        // Inner classes are loaded by the same class loader as the component, but are
-        // not components and are not transformed.
+                // Is it an inner class (does the class name contain a '$')?
+                // Inner classes are loaded by the same class loader as the component, but are
+                // not components and are not transformed.
 
-        if (ctClass.getName().contains("$"))
-            return;
+                if (ctClass.getName().contains("$"))
+                    return;
 
-        // Force the creation of the parent class.
+                // Force the creation of the parent class.
 
-        try
-        {
-            parentClassname = ctClass.getSuperclass().getName();
-        }
-        catch (NotFoundException ex)
-        {
-            throw new RuntimeException(ex);
-        }
+                try
+                {
+                    parentClassname = ctClass.getSuperclass().getName();
+                }
+                catch (NotFoundException ex)
+                {
+                    throw new RuntimeException(ex);
+                }
 
-        String classname = ctClass.getName();
+                String classname = ctClass.getName();
 
-        Logger transformLogger = loggerSource.getLogger("tapestry.transformer." + classname);
-        Logger logger = loggerSource.getLogger(classname);
+                Logger transformLogger = loggerSource.getLogger("tapestry.transformer." + classname);
+                Logger logger = loggerSource.getLogger(classname);
 
-        // If the parent class is in a controlled package, it will already have been loaded and
-        // transformed (that is driven by the ComponentInstantiatorSource).
+                // If the parent class is in a controlled package, it will already have been loaded and
+                // transformed (that is driven by the ComponentInstantiatorSource).
 
-        InternalClassTransformation parentTransformation = nameToClassTransformation.get(parentClassname);
+                InternalClassTransformation parentTransformation = nameToClassTransformation.get(parentClassname);
 
-        // TAPESTRY-2449: Ignore the base class that Groovy can inject
+                // TAPESTRY-2449: Ignore the base class that Groovy can inject
 
-        if (parentTransformation == null
-                && !(parentClassname.equals("java.lang.Object") || parentClassname
-                        .equals("groovy.lang.GroovyObjectSupport")))
-        {
-            String suggestedPackageName = buildSuggestedPackageName(classname);
+                if (parentTransformation == null
+                        && !(parentClassname.equals("java.lang.Object") || parentClassname
+                                .equals("groovy.lang.GroovyObjectSupport")))
+                {
+                    String suggestedPackageName = buildSuggestedPackageName(classname);
 
-            throw new RuntimeException(ServicesMessages.baseClassInWrongPackage(parentClassname, classname,
-                    suggestedPackageName));
-        }
+                    throw new RuntimeException(ServicesMessages.baseClassInWrongPackage(parentClassname, classname,
+                            suggestedPackageName));
+                }
 
-        // TODO: Check that the name is not already in the map. But I think that can't happen,
-        // because the classloader itself is synchronized.
+                // TODO: Check that the name is not already in the map. But I think that can't happen,
+                // because the classloader itself is synchronized.
 
-        Resource baseResource = new ClasspathResource(classname.replace(".", "/") + ".class");
+                Resource baseResource = new ClasspathResource(classname.replace(".", "/") + ".class");
 
-        ComponentModel parentModel = nameToComponentModel.get(parentClassname);
+                ComponentModel parentModel = nameToComponentModel.get(parentClassname);
 
-        MutableComponentModel model = new MutableComponentModelImpl(classname, logger, baseResource, parentModel);
+                MutableComponentModel model = new MutableComponentModelImpl(classname, logger, baseResource,
+                        parentModel);
 
-        InternalClassTransformation transformation = parentTransformation == null ? new InternalClassTransformationImpl(
-                classFactory, ctClass, componentClassCache, model, classSource)
-                : parentTransformation.createChildTransformation(ctClass, model);
+                InternalClassTransformation transformation = parentTransformation == null ? new InternalClassTransformationImpl(
+                        classFactory, ctClass, componentClassCache, model, classSource)
+                        : parentTransformation.createChildTransformation(ctClass, model);
 
-        String transformerDescription = null;
+                String transformerDescription = null;
 
-        try
-        {
-            workerChain.transform(transformation, model);
+                try
+                {
+                    workerChain.transform(transformation, model);
 
-            transformerDescription = transformation.finish();
-        }
-        catch (Throwable ex)
-        {
-            throw new TransformationException(transformation, ex);
-        }
+                    transformerDescription = transformation.finish();
+                }
+                catch (Throwable ex)
+                {
+                    throw new TransformationException(transformation, ex);
+                }
 
-        transformLogger.debug(TapestryMarkers.CLASS_TRANSFORMATION, "Finished class transformation: {}",
-                transformerDescription);
+                transformLogger.debug(TapestryMarkers.CLASS_TRANSFORMATION, "Finished class transformation: {}",
+                        transformerDescription);
 
-        nameToClassTransformation.put(classname, transformation);
-        nameToComponentModel.put(classname, model);
+                nameToClassTransformation.put(classname, transformation);
+                nameToComponentModel.put(classname, model);
+            }
+        });
     }
 
     public Instantiator createInstantiator(String componentClassName)