On Tuesday, October 28, 2003, at 10:35 PM, Daniel L. Rall wrote:


I like your original change to 60 as the default for Anakia, rather than the 2 you just reverted back to. I see the point of Anakia to allow use of Velocity from Ant builds, which are -- usually short-lived -- processes involving static resources. Unless you're generating new resources during build time, a longer interval is more appropriate. If you are generating or modifying resources during a build, you're likely a more advanced developer capable of setting the interval parameter. Just my $0.02 on the likely use case.


I agree wholeheartedly.


But I am not a Texen user, and didn't know if it's appropriate, and didn't want to break anyone. (I assume that you mean 'Texen' wherever you say 'Anakia' above) If the Texen Hoard wants 60, you can have 60 - I have absolutely no opinion, other than I thought 2 sec *was* a bit short too.

geir

- Dan

[EMAIL PROTECTED] wrote:
geirm 2003/10/26 03:05:32
Modified: src/java/org/apache/velocity/texen/ant TexenTask.java
Log:
Turned Hennings change into a parameterization of those settings, because
I'm not sure what his changes would do to others. So old behavior is
restored, but now can be set via params.
Revision Changes Path
1.41 +83 -66 jakarta-velocity/src/java/org/apache/velocity/texen/ant/>> TexenTask.java
Index: TexenTask.java
===================================================================
RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/texen/ant/ TexenTask.java,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -r1.40 -r1.41
--- TexenTask.java 26 Oct 2003 10:54:15 -0000 1.40
+++ TexenTask.java 26 Oct 2003 11:05:32 -0000 1.41
@@ -83,7 +83,7 @@
* @author <a href="[EMAIL PROTECTED]">Robert Burrell Donkin</a>
* @version $Id$
*/
-public class TexenTask +public class TexenTask
extends Task
{
/**
@@ -91,35 +91,35 @@
* invoke ant with the -debug flag) is appended to rethrown
* exception messages.
*/
- private final static String ERR_MSG_FRAGMENT = + private final static String ERR_MSG_FRAGMENT =
". For more information consult the velocity log, or invoke ant " +
"with the -debug flag.";
- +
/**
* This is the control template that governs the output.
* It may or may not invoke the services of worker
* templates.
*/
protected String controlTemplate;
- +
/**
* This is where Velocity will look for templates
* using the file template loader.
*/
protected String templatePath;
- +
/**
* This is where texen will place all the output
* that is a product of the generation process.
*/
protected String outputDirectory;
- +
/**
* This is the file where the generated text
* will be placed.
*/
protected String outputFile;
- +
/**
* This is the encoding for the output file(s).
*/
@@ -147,14 +147,14 @@
* <p>
* For example, if you are generating scripts to allow
* user to automatically create a database, then
- * you might want the <code>$databaseName</code> + * you might want the <code>$databaseName</code>
* to be placed
* in the initial context so that it is available
* in a script that might look something like the
* following:
* <code><pre>
* #!bin/sh
- * + *
* echo y | mysqladmin create $databaseName
* </pre></code>
* The value of <code>$databaseName</code> isn't critical to
@@ -172,6 +172,14 @@
protected boolean useClasspath;
/**
+ * Property which controls whether the resource
+ * loader will be told to cache. Default false
+ */
+
+ protected String useResourceLoaderCache = "false";
+ protected String resourceLoaderModificationCheckInterval = "2";
+
+ /**
* [REQUIRED] Set the control template for the
* generating process.
*/
@@ -194,7 +202,7 @@
* for templates using the file template
* loader.
*/
- +
public void setTemplatePath(String templatePath) throws Exception
{
StringBuffer resolvedPath = new StringBuffer();
@@ -211,7 +219,7 @@
}
}
this.templatePath = resolvedPath.toString();
- +
System.out.println(templatePath);
}
@@ -223,7 +231,7 @@
public String getTemplatePath()
{
return templatePath;
- } + }
/**
* [REQUIRED] Set the output directory. It will be
@@ -240,14 +248,14 @@
throw new BuildException(ioe);
}
}
- +
/**
* Get the output directory.
*/
public String getOutputDirectory()
{
return outputDirectory;
- } + }
/**
* [REQUIRED] Set the output file for the
@@ -257,7 +265,7 @@
{
this.outputFile = outputFile;
}
- +
/**
* Set the output encoding.
*/
@@ -281,7 +289,7 @@
public String getOutputFile()
{
return outputFile;
- } + }
/**
* Set the context properties that will be
@@ -292,17 +300,17 @@
{
String[] sources = StringUtils.split(file,",");
contextProperties = new ExtendedProperties();
- +
// Always try to get the context properties resource
// from a file first. Templates may be taken from a JAR
- // file but the context properties resource may be a + // file but the context properties resource may be a
// resource in the filesystem. If this fails than attempt
// to get the context properties resource from the
// classpath.
for (int i = 0; i < sources.length; i++)
{
ExtendedProperties source = new ExtendedProperties();
- +
try
{
// resolve relative path from basedir and leave
@@ -314,11 +322,11 @@
catch (Exception e)
{
ClassLoader classLoader = this.getClass().getClassLoader();
- +
try
{
InputStream inputStream = classLoader.getResourceAsStream(sources[i]);
- +
if (inputStream == null)
{
throw new BuildException("Context properties file " + sources[i] +
@@ -334,9 +342,9 @@
source = null;
}
}
- +
Iterator j = source.getKeys();
- +
while (j.hasNext())
{
String name = (String) j.next();
@@ -355,7 +363,7 @@
{
return contextProperties;
}
- +
/**
* Set the use of the classpath in locating templates
*
@@ -364,29 +372,38 @@
public void setUseClasspath(boolean useClasspath)
{
this.useClasspath = useClasspath;
- } - + }
+
+ public void setUseResourceLoaderCache(String useResourceLoaderCache)
+ {
+ this.useResourceLoaderCache = useResourceLoaderCache;
+ }
+
+ public void setResourceLoaderModificationCheckInterval(String resourceLoaderModificationCheckInterval)
+ {
+ this.resourceLoaderModificationCheckInterval = resourceLoaderModificationCheckInterval;
+ }
/**
* Creates a VelocityContext.
*
* @return new Context
- * @throws Exception the execute method will catch + * @throws Exception the execute method will catch
* and rethrow as a <code>BuildException</code>
*/
- public Context initControlContext() + public Context initControlContext()
throws Exception
{
return new VelocityContext();
}
- +
/**
* Execute the input script with Velocity
*
- * @throws BuildException + * @throws BuildException
* BuildExceptions are thrown when required attributes are missing.
* Exceptions thrown by Velocity are rethrown as BuildExceptions.
*/
- public void execute () + public void execute ()
throws BuildException
{
// Make sure the template path is set.
@@ -395,28 +412,28 @@
throw new BuildException(
"The template path needs to be defined if you are not using " +
"the classpath for locating templates!");
- } - + }
+
// Make sure the control template is set.
if (controlTemplate == null)
{
throw new BuildException("The control template needs to be defined!");
- } + }
// Make sure the output directory is set.
if (outputDirectory == null)
{
throw new BuildException("The output directory needs to be defined!");
- } - + }
+
// Make sure there is an output file.
if (outputFile == null)
{
throw new BuildException("The output file needs to be defined!");
- } - + }
+
VelocityEngine ve = new VelocityEngine();
- +
try
{
// Setup the Velocity Runtime.
@@ -426,26 +443,26 @@
ve.setProperty(
ve.FILE_RESOURCE_LOADER_PATH, templatePath);
}
- +
if (useClasspath)
{
log("Using classpath");
ve.addProperty(
VelocityEngine.RESOURCE_LOADER, "classpath");
- +
ve.setProperty(
"classpath." + VelocityEngine.RESOURCE_LOADER + ".class",
"org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader") ;
ve.setProperty(
- "classpath." + VelocityEngine.RESOURCE_LOADER + - ".cache", "true");
+ "classpath." + VelocityEngine.RESOURCE_LOADER +
+ ".cache", useResourceLoaderCache);
ve.setProperty(
- "classpath." + VelocityEngine.RESOURCE_LOADER + - ".modificationCheckInterval", "60");
+ "classpath." + VelocityEngine.RESOURCE_LOADER +
+ ".modificationCheckInterval", resourceLoaderModificationCheckInterval);
}
- +
ve.init();
// Create the text generator.
@@ -459,7 +476,7 @@
{
generator.setTemplatePath(templatePath);
}
- +
// Make sure the output directory exists, if it doesn't
// then create it.
File file = new File(outputDirectory);
@@ -467,52 +484,52 @@
{
file.mkdirs();
}
- +
String path = outputDirectory + File.separator + outputFile;
log("Generating to file " + path, project.MSG_INFO);
Writer writer = generator.getWriter(path, outputEncoding);
- +
// The generator and the output path should
// be placed in the init context here and
// not in the generator class itself.
Context c = initControlContext();
- +
// Everything in the generator class should be
// pulled out and placed in here. What the generator
// class does can probably be added to the Velocity
// class and the generator class can probably
// be removed all together.
populateInitialContext(c);
- +
// Feed all the options into the initial
// control context so they are available
// in the control/worker templates.
if (contextProperties != null)
{
Iterator i = contextProperties.getKeys();
- +
while (i.hasNext())
{
String property = (String) i.next();
String value = contextProperties.getString(property);
- +
// Now lets quickly check to see if what
// we have is numeric and try to put it
// into the context as an Integer.
try
{
- c.put(property, new Integer(value)); + c.put(property, new Integer(value));
}
catch (NumberFormatException nfe)
{
// Now we will try to place the value into
// the context as a boolean value if it
// maps to a valid boolean value.
- String booleanString = + String booleanString =
contextProperties.testBoolean(value);
- +
if (booleanString != null)
- { + {
c.put(property, new Boolean(booleanString));
}
else
@@ -534,19 +551,19 @@
{
// We need to turn the license file from relative to
// absolute, and let Ant help :)
- value = StringUtils.fileContentsToString( + value = StringUtils.fileContentsToString(
project.resolveFile(value).getCanonicalPath());
- +
property = property.substring(
0, property.indexOf("file.contents") - 1);
}
- +
c.put(property, value);
}
}
}
}
- +
writer.write(generator.parse(controlTemplate, c));
writer.flush();
writer.close();
@@ -560,14 +577,14 @@
catch( MethodInvocationException e )
{
throw new BuildException(
- "Exception thrown by '" + e.getReferenceName() + "." + + "Exception thrown by '" + e.getReferenceName() + "." +
e.getMethodName() +"'" + ERR_MSG_FRAGMENT,
e.getWrappedThrowable());
- } + }
catch( ParseErrorException e )
{
throw new BuildException("Velocity syntax error" + ERR_MSG_FRAGMENT ,e);
- } + }
catch( ResourceNotFoundException e )
{
throw new BuildException("Resource not found" + ERR_MSG_FRAGMENT,e);
@@ -595,7 +612,7 @@
* #execute()} method will catch and rethrow as a
* <code>BuildException</code>.
*/
- protected void populateInitialContext(Context context) + protected void populateInitialContext(Context context)
throws Exception
{
context.put("now", new Date().toString());



--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]


--
Geir Magnusson Jr                                   203-247-1713(m)
[EMAIL PROTECTED]


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to