Author: kylem
Date: Thu Apr 28 11:53:12 2005
New Revision: 165176
URL: http://svn.apache.org/viewcvs?rev=165176&view=rev
Log:
Added new class (VelocityAptLogSystem) that implements the
org.apache.velocity.runtime.log.LogSystem interface. This class acts as a
bridge between Velocity and APT logging systems, forwarding any error or
warning messages generated by Velocity on the APT messager. This means a)
error/warning streams are unified for Velocity-driven codegen initiated by an
annotatin processor, b) Velocity errors will result in compile failures as they
should, and c) velocity.log files will no longer be dropped in the current
directory.
Added:
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/VelocityAptLogSystem.java
Modified:
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/ControlBeanInfo.vm
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/VelocityGenerator.java
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/ControlAnnotationProcessor.java
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/ControlClientAnnotationProcessor.java
Modified:
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/ControlBeanInfo.vm
URL:
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/ControlBeanInfo.vm?rev=165176&r1=165175&r2=165176&view=diff
==============================================================================
---
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/ControlBeanInfo.vm
(original)
+++
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/ControlBeanInfo.vm
Thu Apr 28 11:53:12 2005
@@ -109,9 +109,8 @@
public BeanDescriptor getBeanDescriptor()
{
BeanDescriptor bd = new BeanDescriptor(${bean.className}.class);
- #set ($featureInfo = $intf.featureInfo)
- #if ($featureInfo)
- #initFeatureDescriptor("bd" $featureInfo $bean.shortName)
+ #if ($intf.featureInfo)
+ #initFeatureDescriptor("bd" $intf.featureInfo $bean.shortName)
#else
bd.setName(#localizeString("$bean.shortName"));
bd.setDisplayName(#localizeString("$bean.shortName"));
Added:
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/VelocityAptLogSystem.java
URL:
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/VelocityAptLogSystem.java?rev=165176&view=auto
==============================================================================
---
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/VelocityAptLogSystem.java
(added)
+++
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/VelocityAptLogSystem.java
Thu Apr 28 11:53:12 2005
@@ -0,0 +1,72 @@
+package org.apache.beehive.controls.runtime.generator;
+
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ *
+ * $Header:$
+ */
+import org.apache.velocity.runtime.RuntimeServices;
+import org.apache.velocity.runtime.log.LogSystem;
+
+import com.sun.mirror.apt.Messager;
+
+/**
+ * The VelocityAptLogSystem implements the
<code>org.apache.velocity.runtime.LogSystem</code>
+ * interface for logging messages from Velocity and routes warnings and errors
to the log
+ * system of APT.
+ */
+public class VelocityAptLogSystem implements LogSystem
+{
+ /**
+ * This is the name of the Velocity configuration property that will be
used to pass
+ * the APT environment from the execution environment into the logger
instance. This
+ * property must be set on the VelocityEngine instance, and the value
should be the
+ * <code>com.sun.mirror.apt.Messager</apt> instance that should be used to
log messages.
+ */
+ static final String APT_ENV_PROPERTY = VelocityAptLogSystem.class + "." +
"environment";
+
+ /**
+ * The prefix to apply to Velocity error and warnings before passing to
APT, to make it
+ * easier to identify Velocity output
+ */
+ static final private String MESSAGE_PREFIX = "VELOCITY: ";
+
+ /**
+ * This can be set to true when debugging Velocity codegen templates to
have all output
+ * from Velocity sent to the APT logger
+ */
+ static final private boolean _debugging = false;
+
+ public VelocityAptLogSystem(Messager messager)
+ {
+ _messager = messager;
+ }
+
+ public void init(RuntimeServices rs) throws java.lang.Exception
+ {
+ }
+
+ public void logVelocityMessage(int level, java.lang.String message)
+ {
+ if (level == LogSystem.ERROR_ID)
+ _messager.printError(MESSAGE_PREFIX + message);
+ else if (level == LogSystem.WARN_ID)
+ _messager.printWarning(MESSAGE_PREFIX + message);
+ else if (_debugging)
+ _messager.printNotice(MESSAGE_PREFIX + message);
+ }
+
+ Messager _messager;
+}
Modified:
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/VelocityGenerator.java
URL:
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/VelocityGenerator.java?rev=165176&r1=165175&r2=165176&view=diff
==============================================================================
---
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/VelocityGenerator.java
(original)
+++
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/VelocityGenerator.java
Thu Apr 28 11:53:12 2005
@@ -30,6 +30,9 @@
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.exception.VelocityException;
import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader;
+import org.apache.velocity.runtime.RuntimeConstants;
+
+import com.sun.mirror.apt.AnnotationProcessorEnvironment;
/**
* The VelocityGenerator class is an implementation of CodeGenerator that uses
standard
@@ -37,19 +40,23 @@
*/
public class VelocityGenerator extends CodeGenerator
{
- public VelocityGenerator() throws Exception
+ public VelocityGenerator(AnnotationProcessorEnvironment env) throws
Exception
{
super();
// Create a Velocity engine instance to support codgen
_ve = new VelocityEngine();
- Properties p = new Properties();
- p.setProperty(VelocityEngine.RESOURCE_LOADER, "class");
- p.setProperty("class." + VelocityEngine.RESOURCE_LOADER + ".class",
+ _ve.setProperty(VelocityEngine.RESOURCE_LOADER, "class");
+ _ve.setProperty("class." + VelocityEngine.RESOURCE_LOADER + ".class",
ClasspathResourceLoader.class.getName());
- p.setProperty("velocimacro.library",
+ _ve.setProperty("velocimacro.library",
"org/apache/beehive/controls/runtime/generator/ControlMacros.vm");
- _ve.init(p);
+
+ // Use the VelocityAptLogSystem to bridge Velocity warnings and errors
back to APT
+ VelocityAptLogSystem logger = new
VelocityAptLogSystem(env.getMessager());
+ _ve.setProperty(VelocityEngine.RUNTIME_LOG_LOGSYSTEM, logger);
+
+ _ve.init();
}
/**
Modified:
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/ControlAnnotationProcessor.java
URL:
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/ControlAnnotationProcessor.java?rev=165176&r1=165175&r2=165176&view=diff
==============================================================================
---
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/ControlAnnotationProcessor.java
(original)
+++
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/ControlAnnotationProcessor.java
Thu Apr 28 11:53:12 2005
@@ -156,25 +156,9 @@
AnnotationProcessorEnvironment env =
getAnnotationProcessorEnvironment();
String generatorName = null;
- // BUGBUG: getting the name should be as easy as the code below...
but for some
- // reason the APT option processing is busted, and doesn't parse
-A keys correctly.
- // The entire value of the -Aoption will be the key, and the value
will be 'null'
- // generatorName = env.getOptions().get("-AcontrolGenerator");
- for (String keyName : env.getOptions().keySet())
- {
- if (keyName.startsWith("-AcontrolGenerator="))
- {
- generatorName = keyName.substring(19);
- break;
- }
- }
-
- if (generatorName == null)
- generatorName =
"org.apache.beehive.controls.runtime.generator.VelocityGenerator";
try
{
- Class generatorClass = Class.forName(generatorName);
- _generator = (CodeGenerator)generatorClass.newInstance();
+ _generator = new VelocityGenerator(env);
}
catch (Exception e)
{
Modified:
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/ControlClientAnnotationProcessor.java
URL:
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/ControlClientAnnotationProcessor.java?rev=165176&r1=165175&r2=165176&view=diff
==============================================================================
---
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/ControlClientAnnotationProcessor.java
(original)
+++
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/ControlClientAnnotationProcessor.java
Thu Apr 28 11:53:12 2005
@@ -534,27 +534,10 @@
// Locate the class that wraps the Velocity code generation process
//
AnnotationProcessorEnvironment env =
getAnnotationProcessorEnvironment();
- String generatorName = null;
- // BUGBUG: getting the name should be as easy as the code below...
but for some
- // reason the APT option processing is busted, and doesn't parse
-A keys correctly.
- // The entire value of the -Aoption will be the key, and the value
will be 'null'
- // generatorName = env.getOptions().get("-AcontrolGenerator");
- for (String keyName : env.getOptions().keySet())
- {
- if (keyName.startsWith("-AcontrolGenerator="))
- {
- generatorName = keyName.substring(19);
- break;
- }
- }
-
- if (generatorName == null)
- generatorName =
"org.apache.beehive.controls.runtime.generator.VelocityGenerator";
try
{
- Class generatorClass = Class.forName(generatorName);
- _generator = (CodeGenerator)generatorClass.newInstance();
+ _generator = new VelocityGenerator(env);
}
catch (Exception e)
{