You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@velocity.apache.org by he...@apache.org on 2007/03/25 19:33:10 UTC
svn commit: r522306 - in /velocity/site/tools/velocity-site-doxia-renderer:
./ src/main/java/org/apache/velocity/site/doxia/plugin/
src/main/java/org/apache/velocity/site/doxia/renderer/
src/main/java/org/apache/velocity/site/doxia/runner/ src/main/jav...
Author: henning
Date: Sun Mar 25 10:33:08 2007
New Revision: 522306
URL: http://svn.apache.org/viewvc?view=rev&rev=522306
Log:
Update site renderer to actually work under maven 2.0.5
Added:
velocity/site/tools/velocity-site-doxia-renderer/src/main/java/org/apache/velocity/site/doxia/runner/
velocity/site/tools/velocity-site-doxia-renderer/src/main/java/org/apache/velocity/site/doxia/runner/DefaultVelocityRunner.java (with props)
velocity/site/tools/velocity-site-doxia-renderer/src/main/java/org/apache/velocity/site/doxia/runner/VelocityRunner.java (with props)
velocity/site/tools/velocity-site-doxia-renderer/src/main/java/org/apache/velocity/site/doxia/util/VelocityDoxiaRendererException.java (with props)
velocity/site/tools/velocity-site-doxia-renderer/src/main/java/org/apache/velocity/site/plexus/
velocity/site/tools/velocity-site-doxia-renderer/src/main/java/org/apache/velocity/site/plexus/PlexusKludgeException.java (with props)
velocity/site/tools/velocity-site-doxia-renderer/src/main/java/org/apache/velocity/site/plexus/PlexusKludgeUtils.java (with props)
velocity/site/tools/velocity-site-doxia-renderer/src/main/resources/org/apache/velocity/site/doxia/runner/
- copied from r518083, velocity/site/tools/velocity-site-doxia-renderer/src/main/resources/org/apache/velocity/site/doxia/renderer/
Removed:
velocity/site/tools/velocity-site-doxia-renderer/src/main/java/org/apache/velocity/site/doxia/util/AbstractDoxiaResourceLoader.java
velocity/site/tools/velocity-site-doxia-renderer/src/main/java/org/apache/velocity/site/doxia/util/DefaultDoxiaLibraryLoader.java
velocity/site/tools/velocity-site-doxia-renderer/src/main/java/org/apache/velocity/site/doxia/util/DefaultDoxiaVelocityContextFactory.java
velocity/site/tools/velocity-site-doxia-renderer/src/main/java/org/apache/velocity/site/doxia/util/DoxiaLibraryLoader.java
velocity/site/tools/velocity-site-doxia-renderer/src/main/java/org/apache/velocity/site/doxia/util/DoxiaResourceLoader.java
velocity/site/tools/velocity-site-doxia-renderer/src/main/java/org/apache/velocity/site/doxia/util/DoxiaVelocityContextFactory.java
velocity/site/tools/velocity-site-doxia-renderer/src/main/java/org/apache/velocity/site/doxia/util/PlexusLogger.java
velocity/site/tools/velocity-site-doxia-renderer/src/main/resources/org/apache/velocity/site/doxia/renderer/
Modified:
velocity/site/tools/velocity-site-doxia-renderer/pom.xml
velocity/site/tools/velocity-site-doxia-renderer/src/main/java/org/apache/velocity/site/doxia/plugin/DoxiaVelocityRendererPlugin.java
velocity/site/tools/velocity-site-doxia-renderer/src/main/java/org/apache/velocity/site/doxia/renderer/AbstractVelocityRenderer.java
velocity/site/tools/velocity-site-doxia-renderer/src/main/java/org/apache/velocity/site/doxia/renderer/VelocityAptRenderer.java
velocity/site/tools/velocity-site-doxia-renderer/src/main/java/org/apache/velocity/site/doxia/renderer/VelocityXdocRenderer.java
Modified: velocity/site/tools/velocity-site-doxia-renderer/pom.xml
URL: http://svn.apache.org/viewvc/velocity/site/tools/velocity-site-doxia-renderer/pom.xml?view=diff&rev=522306&r1=522305&r2=522306
==============================================================================
--- velocity/site/tools/velocity-site-doxia-renderer/pom.xml (original)
+++ velocity/site/tools/velocity-site-doxia-renderer/pom.xml Sun Mar 25 10:33:08 2007
@@ -66,7 +66,7 @@
<dependency>
<groupId>org.apache.maven.doxia</groupId>
<artifactId>doxia-core</artifactId>
- <version>1.0-alpha-9-SNAPSHOT</version>
+ <version>1.0-alpha-8</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
@@ -81,7 +81,7 @@
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-container-default</artifactId>
- <version>1.0-alpha-16</version>
+ <version>1.0-alpha-8</version>
</dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
@@ -91,12 +91,12 @@
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>
- <version>2.0.5-SNAPSHOT</version>
+ <version>2.0.5</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
- <version>2.0.5-SNAPSHOT</version>
+ <version>2.0.5</version>
</dependency>
</dependencies>
Modified: velocity/site/tools/velocity-site-doxia-renderer/src/main/java/org/apache/velocity/site/doxia/plugin/DoxiaVelocityRendererPlugin.java
URL: http://svn.apache.org/viewvc/velocity/site/tools/velocity-site-doxia-renderer/src/main/java/org/apache/velocity/site/doxia/plugin/DoxiaVelocityRendererPlugin.java?view=diff&rev=522306&r1=522305&r2=522306
==============================================================================
--- velocity/site/tools/velocity-site-doxia-renderer/src/main/java/org/apache/velocity/site/doxia/plugin/DoxiaVelocityRendererPlugin.java (original)
+++ velocity/site/tools/velocity-site-doxia-renderer/src/main/java/org/apache/velocity/site/doxia/plugin/DoxiaVelocityRendererPlugin.java Sun Mar 25 10:33:08 2007
@@ -24,17 +24,25 @@
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject;
-import org.apache.velocity.site.doxia.util.DoxiaLibraryLoader;
-import org.apache.velocity.site.doxia.util.DoxiaVelocityContextFactory;
+import org.apache.velocity.site.doxia.runner.VelocityRunner;
+import org.apache.velocity.site.doxia.util.VelocityDoxiaRendererException;
import org.apache.velocity.site.doxia.util.VelocityTool;
+import org.apache.velocity.site.doxia.velocity.DoxiaLibraryLoader;
+import org.apache.velocity.site.doxia.velocity.DoxiaVelocityContextFactory;
/**
- * <p>This plugin allows the transfer of configuration and other information that is only
- * available in the Mojo API to the actual extension code. It is tied to the site lifecycle in the pre-site phase, so
+ * <p>This plugin initialized and configures the Velocity engine used to pre-render templates for the Doxia site.
+ * It is tied to the site lifecycle in the pre-site phase, so
* it will have run before the site-plugin itself triggers the Doxia rendering.</p>
*
+ * <p>Due to the fact that Maven changed its internal container hierarchy starting with 2.0.5, it is no longer
+ * trivially possible to inject information into anything that runs in a different plugin. This makes it necessary
+ * to run all Velocity related code inside this plugin, else you will end up with references pulled in from the
+ * plexus-velocity component which uses an older version of Velocity.
+ *
* <p>This plugin can be configured through the POM:</p>
*
* <p>Configuration from the POM about the libraries to use.</p>
@@ -78,6 +86,8 @@
public class DoxiaVelocityRendererPlugin
extends AbstractMojo
{
+ /** Lookup Key for Plexus Container */
+ public static final String CONTAINER_LOOKUP_NAME = "org.apache.velocity.site:velocity-site-doxia-renderer";
/**
* Directory containing the site files. Will be used to load the Velocity Macro files through
@@ -132,24 +142,6 @@
private String outputEncoding;
/**
- * The Velocity Context Factory. This gets managed by Plexus as a singleton and
- * we leverage the fact that this singleton goes through the plugin before Doxia
- * runs.
- *
- * @component
- */
- private DoxiaVelocityContextFactory doxiaVelocityContextFactory;
-
- /**
- * The Velocity Library Loader. This gets managed by Plexus as a singleton and
- * we leverage the fact that this singleton goes through the plugin before Doxia
- * runs.
- *
- * @component
- */
- private DoxiaLibraryLoader doxiaLibraryLoader;
-
- /**
* Configuration from the POM about the libraries to use.
*
* <pre>
@@ -193,6 +185,34 @@
private VelocityTool [] tools;
/**
+ * The Velocity Context Factory. This gets managed by Plexus as a singleton. However as
+ * we are not inside the Mojo API here, we must use the Plexus requirement annotation, not
+ * the Mojo component annotation. Yes, this is important (and confusing, too).
+ *
+ * @component role="org.apache.velocity.site.doxia.velocity.DoxiaVelocityContextFactory"
+ * @required
+ */
+ private DoxiaVelocityContextFactory doxiaVelocityContextFactory;
+
+ /**
+ * The Velocity Library Loader. This gets managed by Plexus as a singleton. However as
+ * we are not inside the Mojo API here, we must use the Plexus requirement annotation, not
+ * the Mojo component annotation. Yes, this is important (and confusing, too).
+ *
+ * @component role="org.apache.velocity.site.doxia.velocity.DoxiaLibraryLoader"
+ * @required
+ */
+ private DoxiaLibraryLoader doxiaLibraryLoader;
+
+ /**
+ * The Runner object which executes the actual rendering.
+ *
+ * @component role="org.apache.velocity.site.doxia.runner.VelocityRunner"
+ * @required
+ */
+ private VelocityRunner runner;
+
+ /**
* <p>Plugin Execution. Must be run in the pre-site phase of the site lifecycle.
* Copies the injected field parameter into the {@link DoxiaVelocityContextFactory}
* and {@link DoxiaLibraryLoader} singletons so that they are available in the
@@ -201,25 +221,24 @@
* <p>TODO: Find out if that is actually legal and/or the recommended way to do.</p>
*
*/
- public void execute()
+ public void execute() throws MojoExecutionException
{
-
- if (doxiaVelocityContextFactory != null)
- {
+ try {
doxiaVelocityContextFactory.addContextElement("siteDirectory", siteDirectory);
doxiaVelocityContextFactory.addContextElement("project", project);
doxiaVelocityContextFactory.addContextElement("localRepository", localRepository);
doxiaVelocityContextFactory.addContextElement("reactorProjects", reactorProjects);
doxiaVelocityContextFactory.addContextElement("inputEncoding", inputEncoding);
doxiaVelocityContextFactory.addContextElement("outputEncoding", outputEncoding);
-
doxiaVelocityContextFactory.setTools(tools);
- }
- if (doxiaLibraryLoader != null)
- {
doxiaLibraryLoader.setKnownLibraries(libraries);
doxiaLibraryLoader.setSiteDirectory(siteDirectory);
+
+ runner.initVelocity();
+
+ } catch (VelocityDoxiaRendererException vdre) {
+ throw new MojoExecutionException("While executing Velocity Render Plugin:", vdre);
}
}
}
Modified: velocity/site/tools/velocity-site-doxia-renderer/src/main/java/org/apache/velocity/site/doxia/renderer/AbstractVelocityRenderer.java
URL: http://svn.apache.org/viewvc/velocity/site/tools/velocity-site-doxia-renderer/src/main/java/org/apache/velocity/site/doxia/renderer/AbstractVelocityRenderer.java?view=diff&rev=522306&r1=522305&r2=522306
==============================================================================
--- velocity/site/tools/velocity-site-doxia-renderer/src/main/java/org/apache/velocity/site/doxia/renderer/AbstractVelocityRenderer.java (original)
+++ velocity/site/tools/velocity-site-doxia-renderer/src/main/java/org/apache/velocity/site/doxia/renderer/AbstractVelocityRenderer.java Sun Mar 25 10:33:08 2007
@@ -19,32 +19,25 @@
* under the License.
*/
-import java.io.IOException;
-import java.io.InputStream;
import java.io.Reader;
import java.io.StringReader;
-import java.io.StringWriter;
-import java.util.Iterator;
+import java.lang.reflect.Method;
-import org.apache.commons.collections.ExtendedProperties;
-import org.apache.commons.collections.iterators.ArrayIterator;
-import org.apache.commons.lang.StringUtils;
import org.apache.maven.doxia.parser.AbstractParser;
import org.apache.maven.doxia.parser.ParseException;
import org.apache.maven.doxia.parser.Parser;
import org.apache.maven.doxia.sink.Sink;
-import org.apache.velocity.Template;
-import org.apache.velocity.VelocityContext;
-import org.apache.velocity.app.VelocityEngine;
-import org.apache.velocity.runtime.RuntimeConstants;
-import org.apache.velocity.site.doxia.util.DoxiaLibraryLoader;
-import org.apache.velocity.site.doxia.util.DoxiaResourceLoader;
-import org.apache.velocity.site.doxia.util.DoxiaVelocityContextFactory;
-import org.apache.velocity.site.doxia.util.PlexusLogger;
-import org.codehaus.plexus.logging.LogEnabled;
-import org.codehaus.plexus.logging.Logger;
-import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
-import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
+import org.apache.velocity.site.doxia.plugin.DoxiaVelocityRendererPlugin;
+import org.apache.velocity.site.doxia.runner.DefaultVelocityRunner;
+import org.apache.velocity.site.doxia.runner.VelocityRunner;
+import org.apache.velocity.site.plexus.PlexusKludgeException;
+import org.apache.velocity.site.plexus.PlexusKludgeUtils;
+import org.codehaus.plexus.PlexusConstants;
+import org.codehaus.plexus.PlexusContainer;
+import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
+import org.codehaus.plexus.context.Context;
+import org.codehaus.plexus.context.ContextException;
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
/**
@@ -62,48 +55,23 @@
*/
public abstract class AbstractVelocityRenderer
extends AbstractParser
- implements Initializable,
- LogEnabled
-{
-
- /** Plexus Logger object. Injected by {@link LogEnabled} interface. */
- private Logger logger = null;
-
- /**
- * Velocity Engine instance. Now you could argue that Plexus offers a Velocity component
- * that could be used. However what this component not offers is an actual Engine instance
- * but a configured singleton. This parser lives from the fact that we can customize its
- * configuration, its loaders and macro libraries. Nothing of this is offered by the Plexus Velocity component
- * so it is not usable here.
- */
- private VelocityEngine engine = null;
+ implements Contextualizable
- /** Loader that reads the templates from the input reader. */
- private DoxiaResourceLoader doxiaResourceLoader = null;
+{
+ protected PlexusContainer container = null;
- /**
- * The Velocity Context Factory. This gets managed by Plexus as a singleton. However as
- * we are not inside the Mojo API here, we must use the Plexus requirement annotation, not
- * the Mojo component annotation. Yes, this is important (and confusing, too).
- *
- * @plexus.requirement role="org.apache.velocity.site.doxia.util.DoxiaVelocityContextFactory"
- */
- private DoxiaVelocityContextFactory doxiaVelocityContextFactory;
-
- /**
- * The Velocity Library Loader. This gets managed by Plexus as a singleton. However as
- * we are not inside the Mojo API here, we must use the Plexus requirement annotation, not
- * the Mojo component annotation. Yes, this is important (and confusing, too).
- *
- * @plexus.requirement role="org.apache.velocity.site.doxia.util.DoxiaLibraryLoader"
- */
- private DoxiaLibraryLoader doxiaLibraryLoader;
+ private final String roleHint;
/**
* Creates a new AbstractVelocityRenderer object.
*/
- protected AbstractVelocityRenderer()
+ protected AbstractVelocityRenderer(final String roleHint)
{
+ this.roleHint = roleHint;
+ }
+
+ public void contextualize(final Context context) throws ContextException {
+ this.container = (PlexusContainer) context.get(PlexusConstants.PLEXUS_KEY);
}
/**
@@ -112,174 +80,55 @@
*
* @return A {@link Parser} instance that is the actual parser for this document type once Velocity processed the template.
*/
- protected abstract Parser getParser();
-
- /**
- * Returns the Velocity Context factory which contains the values set by the Plugin for the Velocity renderer.
- *
- * It must be injected into an instance of this component.
- *
- * @return A {@link DoxiaVelocityContextFactory} instance that generates
- * {@link VelocityContext} objects for the render process.
- */
- protected DoxiaVelocityContextFactory getContextFactory()
- {
- return doxiaVelocityContextFactory;
- }
-
- /**
- * Returns a {@link org.apache.velocity.runtime.resource.loader.ResourceLoader} to load macro libraries. Its libraries are
- * configured through the plugin.
- *
- * It must be injected into an instance of this component.
- *
- * @return A {@link org.apache.velocity.runtime.resource.loader.ResourceLoader} object.
- */
- protected DoxiaLibraryLoader getLibraryLoader()
- {
- return doxiaLibraryLoader;
- }
-
- /**
- * Returns the Plexus logger.
- *
- * @return The Plexus logger object.
- */
- protected Logger getLogger()
- {
- return logger;
+ protected Parser getParser() throws ComponentLookupException {
+ return (Parser) container.lookup(Parser.ROLE, roleHint);
}
/**
- * Plexus logging. Defined by {@link LogEnabled}.
+ * This is the actual parsing stage. We fetch the Runner object from
+ * the doxia-renderer plugin and execute the parse method on it.
*
- * @param logger A {@link Logger} object.
- */
- public void enableLogging(final Logger logger)
- {
- this.logger = logger;
- }
-
- /**
- * Plexus Lifecycle. Defined by {@link Initializable}.
+ * @param reader The reader which returns the actual template data.
+ * @param sink The Doxia Sink to send our information to.
*
- * @throws InitializationException When the Velocity Engine could not be configured.
+ * @throws parseException When Velocity can not load or process the template.
*/
- public void initialize()
- throws InitializationException
+ public final synchronized void parse(final Reader reader, final Sink sink)
+ throws ParseException
{
- engine = new VelocityEngine();
- doxiaResourceLoader = new DoxiaResourceLoader(logger);
-
- InputStream inputStream = null;
- ExtendedProperties properties = new ExtendedProperties();
-
- // We load a default properties file from the classpath. This file in in the src/main/resources directory
- // It is intentionally *NOT* named velocity.properties!
- try
- {
- inputStream = getClass().getResourceAsStream("doxia-velocity-renderer.properties");
- properties.load(inputStream);
- }
- catch (IOException ioe)
- {
- logger.error("Could not load Default properties: ", ioe);
- }
- finally
- {
- if (inputStream != null)
- {
- try
- {
- inputStream.close();
- }
- catch (IOException ioe2)
- {
- logger.error("While closing Stream: ", ioe2);
- }
- }
- }
-
- engine.setExtendedProperties(properties);
-
- // We have a custom Plexus Logger for Velocity messages.
- engine.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM,
- new PlexusLogger(logger));
-
- // Add the Resource Loader instance to the Velocity configuration.
- engine.setProperty("doxia-loader."
- + RuntimeConstants.RESOURCE_LOADER
- + ".instance", doxiaResourceLoader);
-
- // Add the Library loader to the Velocity configuration.
- DoxiaLibraryLoader libraryLoader = getLibraryLoader();
-
- engine.setProperty("doxia-library-loader."
- + RuntimeConstants.RESOURCE_LOADER
- + ".instance", libraryLoader);
+ try {
+ Object runner = getVelocityRunner();
+ Method parseVelocity = runner.getClass().getMethod(VelocityRunner.PARSE_METHOD, VelocityRunner.PARSE_METHOD_SIGNATURE);
+ String result = (String) parseVelocity.invoke(runner, new Object [] { reader });
- // Add all configured Velocity Macro libraries to the configuration. So they are loaded immediately at init time.
- String[] knownLibraries = libraryLoader.getKnownLibraries();
+ StringReader strReader = new StringReader(result);
- if (knownLibraries != null)
- {
- for (Iterator it = new ArrayIterator(knownLibraries); it.hasNext();)
- {
- String library = (String) it.next();
-
- if (StringUtils.isNotEmpty(library))
- {
- engine.addProperty(RuntimeConstants.VM_LIBRARY, library);
- }
- }
+ getParser().parse(strReader, sink);
}
-
- try
- {
- engine.init();
+ catch (RuntimeException re) {
+ throw re;
}
catch (Exception e)
{
- throw new InitializationException("Velocity Init:", e);
+ throw new ParseException(e);
}
}
/**
- * This is the actual parsing stage. We pull the template from the Reader
- * using the {@link DoxiaResourceLoader}, render the Template into a String
- * and then pass the actual rendering to the injected Renderer (Xdoc or Apt).
+ * Returns the Velocity Context factory which contains the values set by the Plugin for the Velocity renderer.
*
- * @param reader The reader which returns the actual template data.
- * @param sink The Doxia Sink to send our information to.
+ * It must be injected into an instance of this component.
*
- * @throws parseException When Velocity can not load or process the template.
+ * @return A {@link DoxiaVelocityContextFactory} instance that generates
+ * {@link VelocityContext} objects for the render process.
*/
- public final synchronized void parse(final Reader reader, final Sink sink)
- throws ParseException
+ private Object getVelocityRunner() throws ComponentLookupException
{
- // Set the Reader in the Resource loader.
- doxiaResourceLoader.setTemplateReader(reader);
-
- try
- {
-
- // Name must be the empty string so the doxia-loader gets hit.
- Template renderTemplate = engine.getTemplate("");
- VelocityContext ctx = getContextFactory().getVelocityContext();
-
- StringWriter writer = new StringWriter();
-
- renderTemplate.merge(ctx, writer);
- writer.flush();
-
- StringReader strReader = new StringReader(writer.toString());
-
- getParser().parse(strReader, sink);
-
- }
- catch (Exception e)
- {
- throw new ParseException(e);
+ try {
+ PlexusContainer velocityContainer = PlexusKludgeUtils.lookupContainer(container, DoxiaVelocityRendererPlugin.CONTAINER_LOOKUP_NAME);
+ return velocityContainer.lookup(DefaultVelocityRunner.ROLE);
+ } catch (PlexusKludgeException pke) {
+ throw new ComponentLookupException("While retrieving Velocity runner: ", pke);
}
}
}
Modified: velocity/site/tools/velocity-site-doxia-renderer/src/main/java/org/apache/velocity/site/doxia/renderer/VelocityAptRenderer.java
URL: http://svn.apache.org/viewvc/velocity/site/tools/velocity-site-doxia-renderer/src/main/java/org/apache/velocity/site/doxia/renderer/VelocityAptRenderer.java?view=diff&rev=522306&r1=522305&r2=522306
==============================================================================
--- velocity/site/tools/velocity-site-doxia-renderer/src/main/java/org/apache/velocity/site/doxia/renderer/VelocityAptRenderer.java (original)
+++ velocity/site/tools/velocity-site-doxia-renderer/src/main/java/org/apache/velocity/site/doxia/renderer/VelocityAptRenderer.java Sun Mar 25 10:33:08 2007
@@ -19,7 +19,6 @@
* under the License.
*/
-import org.apache.maven.doxia.parser.Parser;
/**
@@ -38,20 +37,6 @@
*/
public VelocityAptRenderer()
{
- }
-
- /**
- * Here we get the actual apt parser from the Doxia core. It will render our processed template.
- *
- * @plexus.requirement role="org.apache.maven.doxia.parser.Parser" role-hint="apt"
- */
- private Parser parser;
-
- /**
- * @see AbstractVelocityRenderer#getParser()
- */
- protected Parser getParser()
- {
- return parser;
+ super("apt");
}
}
Modified: velocity/site/tools/velocity-site-doxia-renderer/src/main/java/org/apache/velocity/site/doxia/renderer/VelocityXdocRenderer.java
URL: http://svn.apache.org/viewvc/velocity/site/tools/velocity-site-doxia-renderer/src/main/java/org/apache/velocity/site/doxia/renderer/VelocityXdocRenderer.java?view=diff&rev=522306&r1=522305&r2=522306
==============================================================================
--- velocity/site/tools/velocity-site-doxia-renderer/src/main/java/org/apache/velocity/site/doxia/renderer/VelocityXdocRenderer.java (original)
+++ velocity/site/tools/velocity-site-doxia-renderer/src/main/java/org/apache/velocity/site/doxia/renderer/VelocityXdocRenderer.java Sun Mar 25 10:33:08 2007
@@ -19,7 +19,6 @@
* under the License.
*/
-import org.apache.maven.doxia.parser.Parser;
/**
@@ -38,20 +37,6 @@
*/
public VelocityXdocRenderer()
{
- }
-
- /**
- * Here we get the actual apt parser from the Doxia core. It will render our processed template.
- *
- * @plexus.requirement role="org.apache.maven.doxia.parser.Parser" role-hint="xdoc"
- */
- private Parser parser;
-
- /**
- * @see AbstractVelocityRenderer#getParser()
- */
- protected Parser getParser()
- {
- return parser;
+ super("xdoc");
}
}
Added: velocity/site/tools/velocity-site-doxia-renderer/src/main/java/org/apache/velocity/site/doxia/runner/DefaultVelocityRunner.java
URL: http://svn.apache.org/viewvc/velocity/site/tools/velocity-site-doxia-renderer/src/main/java/org/apache/velocity/site/doxia/runner/DefaultVelocityRunner.java?view=auto&rev=522306
==============================================================================
--- velocity/site/tools/velocity-site-doxia-renderer/src/main/java/org/apache/velocity/site/doxia/runner/DefaultVelocityRunner.java (added)
+++ velocity/site/tools/velocity-site-doxia-renderer/src/main/java/org/apache/velocity/site/doxia/runner/DefaultVelocityRunner.java Sun Mar 25 10:33:08 2007
@@ -0,0 +1,212 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.velocity.site.doxia.runner;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+import java.io.StringWriter;
+import java.util.Iterator;
+
+import org.apache.commons.collections.ExtendedProperties;
+import org.apache.commons.collections.iterators.ArrayIterator;
+import org.apache.commons.lang.StringUtils;
+import org.apache.velocity.Template;
+import org.apache.velocity.VelocityContext;
+import org.apache.velocity.app.VelocityEngine;
+import org.apache.velocity.runtime.RuntimeConstants;
+import org.apache.velocity.site.doxia.util.VelocityDoxiaRendererException;
+import org.apache.velocity.site.doxia.velocity.DoxiaLibraryLoader;
+import org.apache.velocity.site.doxia.velocity.DoxiaResourceLoader;
+import org.apache.velocity.site.doxia.velocity.DoxiaVelocityContextFactory;
+import org.apache.velocity.site.doxia.velocity.PlexusLogger;
+import org.codehaus.plexus.logging.LogEnabled;
+import org.codehaus.plexus.logging.Logger;
+
+
+
+/**
+ * @plexus.component role="org.apache.velocity.site.doxia.runner.VelocityRunner"
+ *
+ * @author <a href="mailto:henning@apache.org">Henning P. Schmiedehausen</a>
+ * @version $Revision$
+ */
+public final class DefaultVelocityRunner implements VelocityRunner, LogEnabled {
+
+ /** Plexus Logger object */
+ private Logger logger = null;
+
+ /**
+ * Velocity Engine instance. Now you could argue that Plexus offers a Velocity component
+ * that could be used. However what this component not offers is an actual Engine instance
+ * but a configured singleton. This parser lives from the fact that we can customize its
+ * configuration, its loaders and macro libraries. Nothing of this is offered by the Plexus Velocity component
+ * so it is not usable here.
+ */
+ private final VelocityEngine engine;
+
+ /**
+ * The Velocity Context Factory. This gets managed by Plexus as a singleton. However as
+ * we are not inside the Mojo API here, we must use the Plexus requirement annotation, not
+ * the Mojo component annotation. Yes, this is important (and confusing, too).
+ *
+ * @plexus.requirement role="org.apache.velocity.site.doxia.velocity.DoxiaVelocityContextFactory"
+ */
+ private DoxiaVelocityContextFactory doxiaVelocityContextFactory;
+
+ /**
+ * The Velocity Library Loader. This gets managed by Plexus as a singleton. However as
+ * we are not inside the Mojo API here, we must use the Plexus requirement annotation, not
+ * the Mojo component annotation. Yes, this is important (and confusing, too).
+ *
+ * @plexus.requirement role="org.apache.velocity.site.doxia.velocity.DoxiaLibraryLoader"
+ */
+ private DoxiaLibraryLoader doxiaLibraryLoader;
+
+ /**
+ * Logger for Velocity.
+ *
+ * @plexus.requirement role="org.apache.velocity.site.doxia.velocity.PlexusLogger"
+ */
+ private PlexusLogger plexusLogger;
+
+
+ /**
+ * The Velocity Resource Loader.
+ *
+ * @plexus.requirement role="org.apache.velocity.site.doxia.velocity.DoxiaResourceLoader"
+ */
+ private DoxiaResourceLoader doxiaResourceLoader;
+
+ public DefaultVelocityRunner() {
+ this.engine = new VelocityEngine();
+ }
+
+ /**
+ * @see LogEnabled#enableLogging(Logger)
+ */
+ public void enableLogging(final Logger logger)
+ {
+ this.logger = logger;
+ }
+
+ public void initVelocity() throws VelocityDoxiaRendererException {
+
+ InputStream inputStream = null;
+ ExtendedProperties properties = new ExtendedProperties();
+
+ // We load a default properties file from the classpath. This file in in the src/main/resources directory
+ // It is intentionally *NOT* named velocity.properties!
+ try
+ {
+ inputStream = getClass().getResourceAsStream("doxia-velocity-renderer.properties");
+ properties.load(inputStream);
+ }
+ catch (IOException ioe)
+ {
+ logger.error("Could not load Default properties: ", ioe);
+ }
+ finally
+ {
+ if (inputStream != null)
+ {
+ try
+ {
+ inputStream.close();
+ }
+ catch (IOException ioe2)
+ {
+ logger.error("While closing Stream: ", ioe2);
+ }
+ }
+ }
+
+ engine.setExtendedProperties(properties);
+
+ // We have a custom Plexus Logger for Velocity messages.
+ engine.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM, plexusLogger);
+
+ // Add the Resource Loader instance to the Velocity configuration.
+ engine.setProperty("doxia-loader."
+ + RuntimeConstants.RESOURCE_LOADER
+ + ".instance", doxiaResourceLoader);
+
+ engine.setProperty("doxia-library-loader."
+ + RuntimeConstants.RESOURCE_LOADER
+ + ".instance", doxiaLibraryLoader);
+
+ // Add all configured Velocity Macro libraries to the configuration, so they are loaded immediately at init time.
+ String[] knownLibraries = doxiaLibraryLoader.getKnownLibraries();
+
+ if (knownLibraries != null)
+ {
+ for (Iterator it = new ArrayIterator(knownLibraries); it.hasNext();)
+ {
+ String library = (String) it.next();
+
+ if (StringUtils.isNotEmpty(library))
+ {
+ engine.addProperty(RuntimeConstants.VM_LIBRARY, library);
+ }
+ }
+ }
+
+ try
+ {
+ engine.init();
+ }
+ catch (RuntimeException re) {
+ throw re;
+ }
+ catch (Exception e)
+ {
+ throw new VelocityDoxiaRendererException("Velocity Init:", e);
+ }
+ }
+
+ /**
+ * This is the actual parsing stage. We pull the template from the Reader
+ * using the {@link DoxiaResourceLoader}, render the Template into a String
+ * and then pass the actual rendering to the injected Renderer (Xdoc or Apt).
+ *
+ * @param reader The reader which returns the actual template data.
+ * @param sink The Doxia Sink to send our information to.
+ *
+ * @throws parseException When Velocity can not load or process the template.
+ */
+ public final synchronized String parseVelocity(final Reader reader)
+ throws Exception
+ {
+ // Set the Reader in the Resource loader.
+ doxiaResourceLoader.setTemplateReader(reader);
+
+ // Name must be the empty string so the doxia-loader gets hit.
+ Template renderTemplate = engine.getTemplate("");
+ VelocityContext ctx = doxiaVelocityContextFactory.getVelocityContext();
+
+ StringWriter writer = new StringWriter();
+
+ renderTemplate.merge(ctx, writer);
+ writer.flush();
+
+ return writer.toString();
+ }
+}
+
+
Propchange: velocity/site/tools/velocity-site-doxia-renderer/src/main/java/org/apache/velocity/site/doxia/runner/DefaultVelocityRunner.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: velocity/site/tools/velocity-site-doxia-renderer/src/main/java/org/apache/velocity/site/doxia/runner/DefaultVelocityRunner.java
------------------------------------------------------------------------------
svn:keywords = Id Author Date Revision
Added: velocity/site/tools/velocity-site-doxia-renderer/src/main/java/org/apache/velocity/site/doxia/runner/VelocityRunner.java
URL: http://svn.apache.org/viewvc/velocity/site/tools/velocity-site-doxia-renderer/src/main/java/org/apache/velocity/site/doxia/runner/VelocityRunner.java?view=auto&rev=522306
==============================================================================
--- velocity/site/tools/velocity-site-doxia-renderer/src/main/java/org/apache/velocity/site/doxia/runner/VelocityRunner.java (added)
+++ velocity/site/tools/velocity-site-doxia-renderer/src/main/java/org/apache/velocity/site/doxia/runner/VelocityRunner.java Sun Mar 25 10:33:08 2007
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.velocity.site.doxia.runner;
+
+import java.io.Reader;
+
+import org.apache.velocity.site.doxia.util.VelocityDoxiaRendererException;
+
+public interface VelocityRunner {
+
+ /** Plexus Role Definition */
+ public static final String ROLE = VelocityRunner.class.getName();
+
+ public static final String PARSE_METHOD = "parseVelocity";
+
+ public static final Class [] PARSE_METHOD_SIGNATURE = new Class [] { Reader.class};
+
+ void initVelocity() throws VelocityDoxiaRendererException;
+
+ String parseVelocity(final Reader reader) throws Exception;
+}
+
+
+
+
Propchange: velocity/site/tools/velocity-site-doxia-renderer/src/main/java/org/apache/velocity/site/doxia/runner/VelocityRunner.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: velocity/site/tools/velocity-site-doxia-renderer/src/main/java/org/apache/velocity/site/doxia/runner/VelocityRunner.java
------------------------------------------------------------------------------
svn:keywords = Id Author Date Revision
Added: velocity/site/tools/velocity-site-doxia-renderer/src/main/java/org/apache/velocity/site/doxia/util/VelocityDoxiaRendererException.java
URL: http://svn.apache.org/viewvc/velocity/site/tools/velocity-site-doxia-renderer/src/main/java/org/apache/velocity/site/doxia/util/VelocityDoxiaRendererException.java?view=auto&rev=522306
==============================================================================
--- velocity/site/tools/velocity-site-doxia-renderer/src/main/java/org/apache/velocity/site/doxia/util/VelocityDoxiaRendererException.java (added)
+++ velocity/site/tools/velocity-site-doxia-renderer/src/main/java/org/apache/velocity/site/doxia/util/VelocityDoxiaRendererException.java Sun Mar 25 10:33:08 2007
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.velocity.site.doxia.util;
+
+/**
+ * Generic Exception for the news extension.
+ */
+
+public class VelocityDoxiaRendererException
+ extends Exception
+{
+ private static final long serialVersionUID = 1L;
+
+ public VelocityDoxiaRendererException(final String message)
+ {
+ super(message);
+ }
+
+ public VelocityDoxiaRendererException(final Throwable cause)
+ {
+ super(cause);
+ }
+
+ public VelocityDoxiaRendererException(final String message, final Throwable cause)
+ {
+ super(message, cause);
+ }
+}
Propchange: velocity/site/tools/velocity-site-doxia-renderer/src/main/java/org/apache/velocity/site/doxia/util/VelocityDoxiaRendererException.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: velocity/site/tools/velocity-site-doxia-renderer/src/main/java/org/apache/velocity/site/doxia/util/VelocityDoxiaRendererException.java
------------------------------------------------------------------------------
svn:keywords = Id Author Date Revision
Added: velocity/site/tools/velocity-site-doxia-renderer/src/main/java/org/apache/velocity/site/plexus/PlexusKludgeException.java
URL: http://svn.apache.org/viewvc/velocity/site/tools/velocity-site-doxia-renderer/src/main/java/org/apache/velocity/site/plexus/PlexusKludgeException.java?view=auto&rev=522306
==============================================================================
--- velocity/site/tools/velocity-site-doxia-renderer/src/main/java/org/apache/velocity/site/plexus/PlexusKludgeException.java (added)
+++ velocity/site/tools/velocity-site-doxia-renderer/src/main/java/org/apache/velocity/site/plexus/PlexusKludgeException.java Sun Mar 25 10:33:08 2007
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.velocity.site.plexus;
+
+/**
+ * Generic Exception for the news extension.
+ */
+
+public class PlexusKludgeException
+ extends Exception
+{
+ private static final long serialVersionUID = 1L;
+
+ public PlexusKludgeException(final String message)
+ {
+ super(message);
+ }
+
+ public PlexusKludgeException(final Throwable cause)
+ {
+ super(cause);
+ }
+
+ public PlexusKludgeException(final String message, final Throwable cause)
+ {
+ super(message, cause);
+ }
+}
Propchange: velocity/site/tools/velocity-site-doxia-renderer/src/main/java/org/apache/velocity/site/plexus/PlexusKludgeException.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: velocity/site/tools/velocity-site-doxia-renderer/src/main/java/org/apache/velocity/site/plexus/PlexusKludgeException.java
------------------------------------------------------------------------------
svn:keywords = Id Author Date Revision
Added: velocity/site/tools/velocity-site-doxia-renderer/src/main/java/org/apache/velocity/site/plexus/PlexusKludgeUtils.java
URL: http://svn.apache.org/viewvc/velocity/site/tools/velocity-site-doxia-renderer/src/main/java/org/apache/velocity/site/plexus/PlexusKludgeUtils.java?view=auto&rev=522306
==============================================================================
--- velocity/site/tools/velocity-site-doxia-renderer/src/main/java/org/apache/velocity/site/plexus/PlexusKludgeUtils.java (added)
+++ velocity/site/tools/velocity-site-doxia-renderer/src/main/java/org/apache/velocity/site/plexus/PlexusKludgeUtils.java Sun Mar 25 10:33:08 2007
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.velocity.site.plexus;
+
+import java.lang.reflect.Field;
+
+import org.codehaus.classworlds.ClassRealm;
+import org.codehaus.classworlds.NoSuchRealmException;
+import org.codehaus.plexus.PlexusContainer;
+
+public abstract class PlexusKludgeUtils {
+
+ private PlexusKludgeUtils() {
+ }
+
+ public static void bindRealm(final PlexusContainer srcContainer, final PlexusContainer targetContainer, final String packageName) throws PlexusKludgeException {
+ try {
+ if (srcContainer != targetContainer) {
+ ClassRealm srcRealm = srcContainer.getContainerRealm();
+ ClassRealm targetRealm = targetContainer.getContainerRealm();
+ targetRealm.importFrom(srcRealm.getId(), packageName);
+ }
+ } catch (NoSuchRealmException nsre) {
+ throw new PlexusKludgeException(nsre);
+ }
+ }
+
+ public static PlexusContainer lookupContainer(final PlexusContainer container, final String childName) throws PlexusKludgeException {
+
+ try {
+ Field parentContainerField = container.getClass().getDeclaredField("parentContainer");
+ parentContainerField.setAccessible(true);
+ PlexusContainer parentContainer = (PlexusContainer) parentContainerField.get(container);
+
+ if (parentContainer == null) {
+ // Found the root container
+ return container.getChildContainer(childName);
+ } else {
+ return lookupContainer(parentContainer, childName);
+ }
+ } catch (SecurityException se) {
+ throw new PlexusKludgeException(se);
+ } catch (NoSuchFieldException nsme) {
+ throw new PlexusKludgeException(nsme);
+ } catch (IllegalArgumentException iae) {
+ throw new PlexusKludgeException(iae);
+ } catch (IllegalAccessException iae) {
+ throw new PlexusKludgeException(iae);
+ }
+ }
+}
+
+
Propchange: velocity/site/tools/velocity-site-doxia-renderer/src/main/java/org/apache/velocity/site/plexus/PlexusKludgeUtils.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: velocity/site/tools/velocity-site-doxia-renderer/src/main/java/org/apache/velocity/site/plexus/PlexusKludgeUtils.java
------------------------------------------------------------------------------
svn:keywords = Id Author Date Revision