You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2011/11/03 23:41:42 UTC
svn commit: r1197331 - in
/myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main:
java/org/apache/myfaces/buildtools/maven2/plugin/tagdoc/ resources/META-INF/
Author: lu4242
Date: Thu Nov 3 22:41:42 2011
New Revision: 1197331
URL: http://svn.apache.org/viewvc?rev=1197331&view=rev
Log:
MYFACES-3381 Add @JSFFaceletFunction annotation (include it in JSF tag documentation)
Added:
myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/resources/META-INF/xdoc-facelet-functions.vm (with props)
Modified:
myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/tagdoc/TagdocContentMojo.java
myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/tagdoc/TagdocIndexReport.java
Modified: myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/tagdoc/TagdocContentMojo.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/tagdoc/TagdocContentMojo.java?rev=1197331&r1=1197330&r2=1197331&view=diff
==============================================================================
--- myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/tagdoc/TagdocContentMojo.java (original)
+++ myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/tagdoc/TagdocContentMojo.java Thu Nov 3 22:41:42 2011
@@ -53,6 +53,7 @@ import org.apache.myfaces.buildtools.mav
import org.apache.myfaces.buildtools.maven2.plugin.builder.model.ClassMeta;
import org.apache.myfaces.buildtools.maven2.plugin.builder.model.ComponentMeta;
import org.apache.myfaces.buildtools.maven2.plugin.builder.model.ConverterMeta;
+import org.apache.myfaces.buildtools.maven2.plugin.builder.model.FaceletFunctionMeta;
import org.apache.myfaces.buildtools.maven2.plugin.builder.model.FaceletTagMeta;
import org.apache.myfaces.buildtools.maven2.plugin.builder.model.Model;
import org.apache.myfaces.buildtools.maven2.plugin.builder.model.TagMeta;
@@ -180,6 +181,13 @@ public class TagdocContentMojo extends A
private String templateFaceletTag;
/**
+ *
+ * @since 1.0.10
+ * @parameter expression="xdoc-facelet-functions.vm"
+ */
+ private String templateFaceletFunctions;
+
+ /**
* Defines the jsf version (1.1, 1.2 or 2.0), used to pass it and add default
* properties for converters or validators in jsf 2.0.
*
@@ -227,6 +235,18 @@ public class TagdocContentMojo extends A
return false;
}
}
+
+ public boolean canGenerate(FaceletFunctionMeta component)
+ {
+ if (modelIds.contains(component.getModelId()))
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
public class CustomResourceManagerImpl extends ResourceManagerImpl
{
@@ -297,20 +317,26 @@ public class TagdocContentMojo extends A
Iterator tags = model.tags();
Iterator faceletTags = model.faceletTags();
-
+
+ Iterator faceletFunctions = model.faceletFunctions();
+
+ Map<String, List<FaceletFunctionMeta>> faceletFunctionByModelId =
+ new HashMap<String, List<FaceletFunctionMeta>>();
+
Set componentPages = new TreeSet();
Set converterPages = new TreeSet();
Set validatorPages = new TreeSet();
Set behaviorPages = new TreeSet();
Set tagsPages = new TreeSet();
Set faceletTagsPages = new TreeSet();
+ Set faceletFunctionPages = new TreeSet();
int count = 0;
while (components.hasNext())
{
ComponentMeta component = (ComponentMeta) components.next();
if (canGenerate(component))
- {
+ {
String pageName = _generateComponentDoc(velocityEngine,baseContext,model,component);
if (pageName != null)
{
@@ -335,7 +361,7 @@ public class TagdocContentMojo extends A
while (validators.hasNext())
{
ValidatorMeta validator = (ValidatorMeta) validators.next();
-
+
if (canGenerate(validator))
{
String pageName = _generateValidatorDoc(velocityEngine,baseContext,model,validator);
@@ -384,7 +410,29 @@ public class TagdocContentMojo extends A
{
faceletTagsPages.add(pageName);
count++;
- }
+ }
+ }
+ }
+
+ for (int i = 0; i < modelIds.size(); i++)
+ {
+ String modelId = (String) modelIds.get(i);
+
+ faceletFunctionByModelId.put(modelId, new ArrayList<FaceletFunctionMeta>());
+ }
+
+ while (faceletFunctions.hasNext())
+ {
+ FaceletFunctionMeta faceletFunction = (FaceletFunctionMeta) faceletFunctions.next();
+
+ if (canGenerate(faceletFunction))
+ {
+ String pageName = _generateFaceletFunctionDoc(velocityEngine, baseContext, model, faceletFunction);
+ if (pageName != null)
+ {
+ faceletFunctionPages.add(pageName);
+ count++;
+ }
}
}
@@ -940,6 +988,98 @@ public class TagdocContentMojo extends A
return pageName;
}
+ private String _generateFaceletFunctionDoc(
+ VelocityEngine velocityEngine,
+ VelocityContext baseContext,
+ Model model, FaceletFunctionMeta faceletFunction)
+ throws Exception
+ {
+ String pageName = _toPageName(faceletFunction.getName());
+
+ Context context = new VelocityContext(baseContext);
+ context.put("faceletFunction", faceletFunction);
+ context.put("jsf20", new Boolean(_is20()));
+
+ String baseContent = "";
+
+ File xmlBaseFile = new File(baseFilesSourceDirectory,
+ _platformAgnosticPath(pageName + "-base.xml"));
+
+ if (xmlBaseFile != null && xmlBaseFile.exists())
+ {
+ if (getLog().isDebugEnabled())
+ {
+ getLog().debug("using base content file: "+xmlBaseFile.getPath());
+ }
+
+ Reader reader = null;
+ try
+ {
+ reader = new FileReader(xmlBaseFile);
+ Xpp3Dom root = Xpp3DomBuilder.build(reader);
+
+ StringWriter writer = new StringWriter();
+
+ Xpp3Dom [] children = root.getChild("body").getChildren();
+
+ for (int i = 0; i< children.length; i++)
+ {
+ Xpp3Dom dom = children[i];
+ Xpp3DomWriter.write(writer, dom);
+ }
+ baseContent = writer.toString();
+ writer.close();
+ }
+ catch (XmlPullParserException e)
+ {
+ throw new MojoExecutionException(
+ "Error parsing base file: " + e.getMessage(), e);
+ }
+ finally
+ {
+ reader.close();
+ }
+ }
+
+ baseContext.put("baseContent", baseContent);
+
+ Writer out = null;
+
+ try
+ {
+ File targetDir = new File(outputDirectory.getParentFile(),
+ _platformAgnosticPath("generated-site/xdoc/"
+ + _DOC_SUBDIRECTORY));
+
+ if ( !targetDir.exists() )
+ {
+ targetDir.mkdirs();
+ }
+ File targetFile = new File(targetDir, pageName + ".xml");
+
+ out = new OutputStreamWriter(new FileOutputStream(targetFile),
+ "UTF-8");
+
+ Template template = velocityEngine.getTemplate(getTemplateFaceletFunctions());
+
+ template.merge(context, out);
+
+ out.flush();
+ }
+ catch (Exception e)
+ {
+ throw new MojoExecutionException(
+ "Error merging velocity templates: " + e.getMessage(), e);
+ }
+ finally
+ {
+ IOUtil.close(out);
+ out = null;
+ }
+
+ return pageName;
+ }
+
private String _generateFaceletTagDoc(VelocityEngine velocityEngine,
VelocityContext baseContext, Model model, FaceletTagMeta faceletTag)
throws Exception
@@ -1229,6 +1369,11 @@ public class TagdocContentMojo extends A
return templateFaceletTag;
}
+ public String getTemplateFaceletFunctions()
+ {
+ return templateFaceletFunctions;
+ }
+
private boolean _is12()
{
return "1.2".equals(jsfVersion) || "12".equals(jsfVersion);
Modified: myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/tagdoc/TagdocIndexReport.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/tagdoc/TagdocIndexReport.java?rev=1197331&r1=1197330&r2=1197331&view=diff
==============================================================================
--- myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/tagdoc/TagdocIndexReport.java (original)
+++ myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/tagdoc/TagdocIndexReport.java Thu Nov 3 22:41:42 2011
@@ -29,6 +29,8 @@ import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
+import org.apache.maven.doxia.sink.Sink;
+import org.apache.maven.doxia.siterenderer.Renderer;
import org.apache.maven.project.MavenProject;
import org.apache.maven.reporting.AbstractMavenReport;
import org.apache.maven.reporting.MavenReportException;
@@ -38,14 +40,13 @@ import org.apache.myfaces.buildtools.mav
import org.apache.myfaces.buildtools.maven2.plugin.builder.model.ClassMeta;
import org.apache.myfaces.buildtools.maven2.plugin.builder.model.ComponentMeta;
import org.apache.myfaces.buildtools.maven2.plugin.builder.model.ConverterMeta;
+import org.apache.myfaces.buildtools.maven2.plugin.builder.model.FaceletFunctionMeta;
import org.apache.myfaces.buildtools.maven2.plugin.builder.model.FaceletTagMeta;
import org.apache.myfaces.buildtools.maven2.plugin.builder.model.Model;
import org.apache.myfaces.buildtools.maven2.plugin.builder.model.TagMeta;
import org.apache.myfaces.buildtools.maven2.plugin.builder.model.ValidatorMeta;
import org.apache.myfaces.buildtools.maven2.plugin.builder.utils.MyfacesUtils;
import org.apache.velocity.runtime.resource.ResourceManagerImpl;
-import org.apache.maven.doxia.sink.Sink;
-import org.apache.maven.doxia.siterenderer.Renderer;
/**
* Report for generating JSF tagdoc index based on myfaces-metadata.xml parsing.
@@ -158,6 +159,18 @@ public class TagdocIndexReport extends A
return false;
}
}
+
+ public boolean canGenerate(FaceletFunctionMeta component)
+ {
+ if (modelIds.contains(component.getModelId()))
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
public class CustomResourceManagerImpl extends ResourceManagerImpl
{
@@ -189,7 +202,12 @@ public class TagdocIndexReport extends A
Iterator tags = model.tags();
Iterator faceletTags = model.faceletTags();
-
+
+ Iterator faceletFunctions = model.faceletFunctions();
+
+ Map<String, List<FaceletFunctionMeta>> faceletFunctionByModelId =
+ new HashMap<String, List<FaceletFunctionMeta>>();
+
// =-=AEW Note that only updating out-of-date components, etc. is
// permanently tricky, even if we had proper detection in place,
// because the index always has to have all docs
@@ -207,6 +225,7 @@ public class TagdocIndexReport extends A
Set validatorPages = new TreeSet();
Set tagsPages = new TreeSet();
Set faceletTagPages = new TreeSet();
+ Set faceletFunctionPages = new TreeSet();
int count = 0;
while (components.hasNext())
@@ -293,7 +312,28 @@ public class TagdocIndexReport extends A
}
}
+ for (int i = 0; i < modelIds.size(); i++)
+ {
+ String modelId = (String) modelIds.get(i);
+
+ faceletFunctionByModelId.put(modelId, new ArrayList<FaceletFunctionMeta>());
+ }
+ while (faceletFunctions.hasNext())
+ {
+ FaceletFunctionMeta faceletFunction = (FaceletFunctionMeta) faceletFunctions.next();
+
+ if (canGenerate(faceletFunction))
+ {
+ String pageName = _generateFaceletFunctionDoc(model, faceletFunction);
+ if (pageName != null)
+ {
+ faceletFunctionPages.add(pageName);
+ count++;
+ }
+ }
+ }
+
Set otherPages = _gatherOtherTags();
getLog().info("Generated " + count + " page(s)");
@@ -341,6 +381,7 @@ public class TagdocIndexReport extends A
_writeIndexSection(sink, behaviorPages, "Behaviors");
_writeIndexSection(sink, tagsPages, "JSF Tags");
_writeIndexSection(sink, faceletTagPages, "JSF Facelet Tags");
+ _writeIndexSection(sink, faceletFunctionPages, "JSF Facelet EL Functions", "Function Name");
_writeIndexSection(sink, otherPages, "Miscellaneous");
sink.body_();
@@ -370,6 +411,11 @@ public class TagdocIndexReport extends A
private void _writeIndexSection(Sink sink, Set pages, String title)
{
+ _writeIndexSection(sink, pages, title, "Tag Name");
+ }
+
+ private void _writeIndexSection(Sink sink, Set pages, String title, String typeName)
+ {
if (pages.isEmpty())
{
return;
@@ -382,7 +428,7 @@ public class TagdocIndexReport extends A
sink.table();
sink.tableRow();
sink.tableHeaderCell();
- sink.text("Tag Name");
+ sink.text(typeName);
sink.tableHeaderCell_();
sink.tableRow_();
@@ -406,7 +452,7 @@ public class TagdocIndexReport extends A
sink.table_();
sink.section1_();
}
-
+
public boolean usePageLinkBar()
{
return false;
@@ -482,6 +528,19 @@ public class TagdocIndexReport extends A
return pageName;
}
+ private String _generateFaceletFunctionDoc(Model model, FaceletFunctionMeta faceletFunction)
+ throws IOException
+ {
+ if (faceletFunction.getName() == null)
+ {
+ return null;
+ }
+
+ String pageName = _toPageName(faceletFunction.getName());
+
+ return pageName;
+ }
+
private String _generateFaceletTagDoc(Model model, FaceletTagMeta tag)
throws IOException
{
Added: myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/resources/META-INF/xdoc-facelet-functions.vm
URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/resources/META-INF/xdoc-facelet-functions.vm?rev=1197331&view=auto
==============================================================================
--- myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/resources/META-INF/xdoc-facelet-functions.vm (added)
+++ myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/resources/META-INF/xdoc-facelet-functions.vm Thu Nov 3 22:41:42 2011
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<document>
+ <properties>
+ <title><$faceletFunction.name></title>
+ </properties>
+ <body>
+ <section name="Summary">
+ <p>
+ <b>Function name:</b> <$faceletFunction.name>
+ <br/>
+ <b>Function signature:</b> $faceletFunction.declaredSignature
+ <br/>
+#set ($javadocPath = "../apidocs/" + $faceletFunction.getSourceClassName().replace('.', '/') )
+ <b>Source class:</b> <a href="${tagdocUtils.platformAgnosticPath( $javadocPath )}.html">${faceletFunction.sourceClassName}</a>
+ <br/>
+#if ($faceletFunction.longDescription)
+ <b>Description:</b> $faceletFunction.longDescription
+#elseif ($faceletFunction.description)
+ <b>Description:</b> $faceletFunction.description
+#end
+ <br/>
+ </p>
+ </section>
+#if ($baseContent)
+$baseContent
+#end
+ </body>
+</document>
\ No newline at end of file
Propchange: myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/resources/META-INF/xdoc-facelet-functions.vm
------------------------------------------------------------------------------
svn:eol-style = native