Author: nbubna
Date: Tue Feb 24 00:33:17 2009
New Revision: 747236
URL: http://svn.apache.org/viewvc?rev=747236&view=rev
Log:
VELOCITY-704 add deprecation notices for features replaced by the scope
controls and the updated #stop
Modified:
velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Break.java
velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Foreach.java
velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java
Modified:
velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Break.java
URL:
http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Break.java?rev=747236&r1=747235&r2=747236&view=diff
==============================================================================
---
velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Break.java
(original)
+++
velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Break.java
Tue Feb 24 00:33:17 2009
@@ -36,11 +36,15 @@
* Break directive used for interrupting foreach loops.
*
* @author <a href="mailto:[email protected]">Jarkko Viinamaki</a>
+ * @deprecated use {...@link Stop} with {...@link ForeachScope} (e.g.
#stop($foreach) )
* @version $Id$
*/
public class Break extends Directive
{
private static final BreakCommand BREAK = new BreakCommand();
+
+ private boolean warned = false;
+
/**
* Return name of this directive.
* @return The name of this directive.
@@ -94,6 +98,16 @@
+ Log.formatFileString(this));
}
}
+
+ // give deprecation warning once per instance, not on every merge
+ if (!warned)
+ {
+ warned = true;
+ if (rs.getLog().isInfoEnabled())
+ {
+ rs.getLog().info("#break has been deprecated and will be
removed in Velocity 2.0; please use #stop($foreach) instead.");
+ }
+ }
}
/**
Modified:
velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Foreach.java
URL:
http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Foreach.java?rev=747236&r1=747235&r2=747236&view=diff
==============================================================================
---
velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Foreach.java
(original)
+++
velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/Foreach.java
Tue Feb 24 00:33:17 2009
@@ -184,6 +184,9 @@
*/
private String elementKey;
+ // track if we've done the deprecation warning thing already
+ private boolean warned = false;
+
/**
* immutable, so create in init
*/
@@ -202,9 +205,42 @@
{
super.init(rs, context, node);
+ // handle deprecated config settings
counterName = rsvc.getString(RuntimeConstants.COUNTER_NAME);
hasNextName = rsvc.getString(RuntimeConstants.HAS_NEXT_NAME);
counterInitialValue =
rsvc.getInt(RuntimeConstants.COUNTER_INITIAL_VALUE);
+ // only warn once per instance...
+ if (!warned && rsvc.getLog().isInfoEnabled())
+ {
+ warned = true;
+ // ...and only if they customize these settings
+ if (!counterName.equals("velocityCount"))
+ {
+ rsvc.getLog().warn("The "+RuntimeConstants.COUNTER_NAME+
+ " property has been deprecated. It will be removed"+
+ " (along with $velocityCount itself) in Velocity 2.0. "+
+ " Instead, please use $foreach.count to access"+
+ " the loop counter.");
+ }
+ if (!hasNextName.equals("velocityHasNext"))
+ {
+ rsvc.getLog().warn("The "+RuntimeConstants.HAS_NEXT_NAME+
+ " property has been deprecated. It will be removed"+
+ " (along with $velocityHasNext itself ) in Velocity 2.0. "+
+ " Instead, please use $foreach.hasNext to access"+
+ " this value from now on.");
+ }
+ if (counterInitialValue != 1)
+ {
+ rsvc.getLog().warn("The
"+RuntimeConstants.COUNTER_INITIAL_VALUE+
+ " property has been deprecated. It will be removed"+
+ " (along with $velocityCount itself) in Velocity 2.0. "+
+ " Instead, please use $foreach.index to access"+
+ " the 0-based loop index and $foreach.count"+
+ " to access the 1-based loop counter.");
+ }
+ }
+
maxNbrLoops = rsvc.getInt(RuntimeConstants.MAX_NUMBER_LOOPS,
Integer.MAX_VALUE);
if (maxNbrLoops < 1)
Modified:
velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java
URL:
http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java?rev=747236&r1=747235&r2=747236&view=diff
==============================================================================
---
velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java
(original)
+++
velocity/engine/trunk/src/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java
Tue Feb 24 00:33:17 2009
@@ -247,6 +247,24 @@
// support for local context scope feature, where all references are
local
// we do not have to check this at every invocation of ProxyVMContext
localContextScope =
rsvc.getBoolean(RuntimeConstants.VM_CONTEXT_LOCALSCOPE, false);
+ if (localContextScope && rsvc.getLog().isWarnEnabled())
+ {
+ // only warn once per runtime, so this isn't obnoxious
+ String key = "velocimacro.context.localscope.warning";
+ Boolean alreadyWarned = (Boolean)rsvc.getApplicationAttribute(key);
+ if (alreadyWarned == null)
+ {
+ rsvc.setApplicationAttribute(key, Boolean.TRUE);
+ rsvc.getLog()
+ .warn("The "+RuntimeConstants.VM_CONTEXT_LOCALSCOPE+
+ " feature is deprecated and will be removed in Velocity
2.0."+
+ " Instead, please use the $macro scope to store
references"+
+ " that must be local to your macros (e.g. "+
+ "#set( $macro.foo = 'bar' ) and $macro.foo). This
$macro"+
+ " namespace is automatically created and destroyed for
you at"+
+ " the beginning and end of the macro rendering.");
+ }
+ }
// get the macro call depth limit
maxCallDepth = rsvc.getInt(RuntimeConstants.VM_MAX_DEPTH);