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/20 20:26:48 UTC
svn commit: r670023 -
/myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/MakeConfigMojo.java
Author: skitching
Date: Fri Jun 20 11:26:47 2008
New Revision: 670023
URL: http://svn.apache.org/viewvc?rev=670023&view=rev
Log:
Documentation, code layout fixes. No logic changes.
Modified:
myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/MakeConfigMojo.java
Modified: myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/MakeConfigMojo.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/MakeConfigMojo.java?rev=670023&r1=670022&r2=670023&view=diff
==============================================================================
--- myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/MakeConfigMojo.java (original)
+++ myfaces/myfaces-build-tools/trunk/maven2-plugins/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/MakeConfigMojo.java Fri Jun 20 11:26:47 2008
@@ -55,6 +55,29 @@
/**
* Creates taglib (tld) and faces-config files.
+ * <p>
+ * This Mojo actually provides a generic goal that will run a configurable
+ * velocity template file. The template is passed the full metadata model
+ * object, and can select from the model whatever data it wants. Only one
+ * output file can be generated per execution.
+ * <p>
+ * The execution can be configured with:
+ * <ul>
+ * <li>The name of the input template to be executed
+ * <li>The name of the output file to be created
+ * <li>Any number of variables which are accessable from the template
+ * (string values only)
+ * </ul>
+ * <p>
+ * The executed template has the following variables available to it:
+ * <ul>
+ * <li>model: the full metadata model for this project
+ * <li>modelIds: specifies which items from the model should be processed
+ * <li>baseContent: the full text of the contents of the "xmlBaseFile" (if any)
+ * <li>utils: an instance of MyfacesUtils that provides static helper methods
+ * <li>and whatever (name,value) pairs were configured via the "params" property
+ * of this mojo.
+ * </ul>
*
* @requiresDependencyResolution compile
* @goal make-config
@@ -65,72 +88,127 @@
final Logger log = Logger.getLogger(MakeConfigMojo.class.getName());
/**
+ * The current maven project (auto-injected by Maven).
+ *
* @parameter expression="${project}"
* @readonly
*/
private MavenProject project;
/**
+ * The current maven project (auto-injected by Maven).
+ *
+ * TODO: this default value looks wrong. What should really be here?
+ *
* @parameter expression="${project.build.directory}/maven-faces-plugin/main/resources"
* @readonly
*/
private File buildDirectory;
/**
- * Injected name of file generated by earlier run of BuildMetaDataMojo goal.
+ * Name of the file from which the metadata model passed to the
+ * template will be read. This file is typically generated by an earlier
+ * execution of the BuildMetaDataMojo goal for the same maven project.
*
* @parameter
*/
private String metadataFile = "META-INF/myfaces-metadata.xml";
/**
+ * Specifies the name of the output file to be created.
+ *
* @parameter
*/
private String xmlFile = "META-INF/faces-config.xml";
/**
- * modelIds to be applied this goal
+ * A list of metadata model ids.
+ * <p>
+ * If not defined, then this defaults to a list containing just one string whose
+ * value is the same as the current maven project's artifactId.
+ * <p>
+ * The complete metadata model is passed to the velocity template. This contains
+ * data about not just the model items defined in the calling project, but also
+ * about items imported from other projects. Each item in the model is
+ * labelled with a "model id" indicating which project it was defined by.
+ * <p>
+ * This list of model ids is also passed to the template. The template can
+ * then use that data to select the relevant items from the full model.
*
* @parameter
*/
private List modelIds;
/**
+ * The base directory used when resolving references to external files from
+ * velocity #include and #parse commands within the executed template.
+ *
* @parameter expression="src/main/resources/META-INF"
*/
private File templateSourceDirectory;
/**
+ * When defined, specifies an xml file whose top-level elements are to be copied
+ * directly into the created file.
+ * <p>
+ * This allows a hand-written file to be created containing data that cannot be
+ * automatically generated. All content beneath the root element of the specified
+ * file (but not the root element itself) is placed into a Velocity variable
+ * named "baseContent" that the template can reference.
+ * <p>
+ * The template can do whatever it wants with this variable, but it is expected
+ * that the template will simply output this immediately after writing the
+ * root element of the output xml file.
+ * file.
+ * <p>
+ * Note that any attributes or namespaces defined on the root element of the
+ * xmlBaseFile are ignored.
+ *
* @parameter expression="src/main/conf/META-INF/faces-config-base.xml"
*/
private File xmlBaseFile;
-
-
+
/**
+ * Specifies the Velocity template file to be executed.
+ *
* @parameter expression="faces-config11.vm"
*/
private String templateFile;
/**
+ * A map of (name, value) pairs to be made available as Velocity variables
+ * for the executed template to access.
+ *
* @parameter
*/
private Map params;
/**
* Execute the Mojo.
+ * <p>
+ * The metadata model is loaded, and the specified template is executed with
+ * any template output being written to the specified output file.
*/
public void execute() throws MojoExecutionException
{
try
{
- if (modelIds == null){
+ if (modelIds == null)
+ {
modelIds = new ArrayList();
modelIds.add(project.getArtifactId());
}
-
+
+ // Load the metadata file from an xml file (presumably generated
+ // by an earlier execution of the build-metadata goal.
Model model = IOUtils.loadModel(new File(buildDirectory,
metadataFile));
+
+ // Flatten the model so that the template can access every property
+ // of each model item directly, even when the property is actually
+ // defined on an ancestor class or interface.
new Flattener(model).flatten();
+
generateConfigFromVelocity(model);
//throw new MojoExecutionException("Error during config generation");
}
@@ -159,7 +237,8 @@
getLog().info("using base content file: "+xmlBaseFile.getPath());
Reader reader = null;
- try {
+ try
+ {
reader = new FileReader(xmlBaseFile);
Xpp3Dom root = Xpp3DomBuilder.build(reader);
@@ -167,7 +246,8 @@
Xpp3Dom [] children = root.getChildren();
- for (int i = 0; i< children.length; i++){
+ for (int i = 0; i< children.length; i++)
+ {
Xpp3Dom dom = children[i];
Xpp3DomWriter.write(writer, dom);
writer.write('\n');
@@ -179,7 +259,9 @@
{
// TODO Auto-generated catch block
e.printStackTrace();
- }finally{
+ }
+ finally
+ {
reader.close();
}
}
@@ -205,7 +287,8 @@
Writer writer = null;
File outFile = null;
- try {
+ try
+ {
outFile = new File(buildDirectory, xmlFile);
if ( !outFile.getParentFile().exists() )