You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by sk...@apache.org on 2008/06/19 00:03:01 UTC

svn commit: r669310 - in /myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder: BuildMetaDataMojo.java qdox/QdoxModelBuilder.java

Author: skitching
Date: Wed Jun 18 15:03:01 2008
New Revision: 669310

URL: http://svn.apache.org/viewvc?rev=669310&view=rev
Log:
Fix problems with looking up the "logical" parent class. This means that "inherited" model data from other projects must be loaded before source scanning begins. Also delay checking of component class validity until the metadata file has been created; that makes things easier to debug.

Modified:
    myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/BuildMetaDataMojo.java
    myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/qdox/QdoxModelBuilder.java

Modified: myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/BuildMetaDataMojo.java
URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/BuildMetaDataMojo.java?rev=669310&r1=669309&r2=669310&view=diff
==============================================================================
--- myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/BuildMetaDataMojo.java (original)
+++ myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/BuildMetaDataMojo.java Wed Jun 18 15:03:01 2008
@@ -137,7 +137,8 @@
             throw new MojoExecutionException("Error during generation", e);
         }
         
-        Model model = buildModel(project);
+        Model model = new Model();
+
         List models = null;
         if (dependencyModelIds != null)
         {
@@ -162,9 +163,12 @@
             model.merge(artifactModel);
         }
 
+        buildModel(model, project);
         resolveReplacePackage(model);
         
         IOUtils.saveModel(model, new File(targetDirectory, outputFile));
+        
+        validateComponents(model);
     }
     
     /**
@@ -236,12 +240,11 @@
     /**
      * Execute ModelBuilder classes to create the Model data-structure.
      */
-    private Model buildModel(MavenProject project)
+    private Model buildModel(Model model, MavenProject project)
             throws MojoExecutionException
     {
         try
         {
-            Model model = new Model();
             QdoxModelBuilder builder = new QdoxModelBuilder();
             model.setModelId(modelId);
             builder.buildModel(model, project);            
@@ -260,4 +263,86 @@
         resource.setDirectory(resourceRoot);
         resources.add(resource);
     }
+    
+    /**
+     * Check that each component is valid (has all mandatory properties etc).
+     * <p>
+     * Most sanity checks are best done after the myfaces-metadata.xml file
+     * is created, so that if an error occurs the file is available for the
+     * user to inspect. In particular, problems due to missing properties
+     * which are permitted to be inherited can be tricky to track down if
+     * the metadata file is not available.
+     * <p>
+     * TODO: make this gather up all the errors, then report them at once
+     * rather than stopping on the first error found.
+     */
+    private void validateComponents(Model model) throws MojoExecutionException
+    {
+    	for(Iterator i = model.components(); i.hasNext(); )
+    	{
+    		ComponentMeta component = (ComponentMeta) i.next();
+    		validateComponent(model, component);
+    	}
+    }
+    
+    private void validateComponent(Model model, ComponentMeta component)
+    throws MojoExecutionException
+    {
+    	if (component.getName() != null)
+    	{
+            if (component.getDescription() == null)
+            {
+            	throw new MojoExecutionException(
+                		"Missing mandatory property on component " + component.getClassName()
+                		+ " [sourceClass=" + component.getSourceClassName() + "]: description");
+            }
+
+            if (component.getType() == null)
+            {
+            	throw new MojoExecutionException(
+                		"Missing mandatory property on component " + component.getClassName()
+                		+ " [sourceClass=" + component.getSourceClassName() + "]: type");
+            }
+            
+    		// this is a concrete component, so it must have a family property
+    		validateComponentFamily(model, component);
+    	}
+    }
+    
+    private void validateComponentFamily(Model model, ComponentMeta component)
+    throws MojoExecutionException
+    {
+    	// TODO: clean this code up, it is pretty ugly
+        boolean familyDefined = false;
+        ComponentMeta curr = component;
+        while ((curr != null) && !familyDefined)
+        {
+        	if (curr.getFamily() != null)
+        	{
+        		familyDefined = true;
+        	}
+        	else
+        	{
+	        	String parentName = curr.getParentClassName();
+	        	if (parentName == null)
+	        		curr = null;
+	        	else
+	        	{
+	        		curr = model.findComponentByClassName(parentName);
+	        		if (curr == null)
+	        		{
+	                	throw new MojoExecutionException(
+	                    		"Parent class not found for component " + component.getClassName()
+	                    		+ " [sourceClass=" + component.getSourceClassName() + "]");
+	        		}
+	        	}
+        	}
+        }
+        if (!familyDefined)
+        {
+        	throw new MojoExecutionException(
+        		"Missing mandatory property on component " + component.getClassName()
+        		+ " [sourceClass=" + component.getSourceClassName() + "]: family");
+        }
+    }
 }

Modified: myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/qdox/QdoxModelBuilder.java
URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/qdox/QdoxModelBuilder.java?rev=669310&r1=669309&r2=669310&view=diff
==============================================================================
--- myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/qdox/QdoxModelBuilder.java (original)
+++ myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/qdox/QdoxModelBuilder.java Wed Jun 18 15:03:01 2008
@@ -481,7 +481,15 @@
         	modelItem.setClassName(classNameOverride);
         }
         
-        // logical parent (one metadata is inherited from)
+        // Find logical parent (one metadata is inherited from). Note that
+        // the processClass() method ensures that all ancestor classes are
+        // processed before their child classes. So this lookup doesn't have
+        // to deal with the parent not yet having been added to the model.
+        //
+        // The parent class might also have been inherited (merged in) from
+        // some other project; it is the responsibility of the caller of the
+        // buildModel method to ensure that the model passed in already has
+        // the necessary model items in it.
         JavaClass parentClazz = clazz.getSuperJavaClass();
         while (parentClazz != null)
         {
@@ -805,7 +813,6 @@
         processComponentProperties(clazz, component);
         processComponentFacets(clazz, component);
 
-        validateComponent(model, component);
         model.addComponent(component);
     }
 
@@ -1428,69 +1435,4 @@
         // abc.
         return doc.substring(0, index);
     }
-
-    private void validateComponent(Model model, ComponentMeta component)
-            throws MojoExecutionException
-    {
-        // when name is set, this is a real component, so must have
-        // desc, type, family, rendererType,
-        // tagClass, tagSuperclass
-
-        if (component.getName() == null)
-        {
-            return;
-        }
-
-        List badprops = new ArrayList();
-        if (component.getDescription() == null)
-        {
-            badprops.add("description");
-        }
-        if (component.getType() == null)
-        {
-            badprops.add("type");
-        }
-        
-        // Family is mandatory on a concrete component, but can be inherited.
-        // TODO: clean up this loop; it is ugly.
-        boolean familyDefined = false;
-        ComponentMeta curr = component;
-        while ((curr != null) && !familyDefined)
-        {
-        	if (curr.getFamily() != null)
-        		familyDefined = true;
-        	String parentName = curr.getParentClassName();
-        	if (parentName == null)
-        		curr = null;
-        	else
-        		curr = model.findComponentByClassName(parentName);
-        }
-        if (!familyDefined)
-        {
-            badprops.add("family");
-        }
-        
-        //Renderer is optional
-        //if (component.getRendererType() == null)
-        //{
-        //    badprops.add("rendererType");
-        //}
-
-        if (badprops.size() > 0)
-        {
-            StringBuffer buf = new StringBuffer();
-            for (Iterator i = badprops.iterator(); i.hasNext();)
-            {
-                if (buf.length() > 0)
-                {
-                    buf.append(",");
-                }
-                buf.append((String) i.next());
-            }
-            throw new MojoExecutionException(
-                    "Missing properties on component class "
-                            + component.getClassName() + ":" + buf.toString());
-
-        }
-    }
 }
\ No newline at end of file