From 00909c148c56d3626b8abffdd8c98a5f4196b7be Mon Sep 17 00:00:00 2001 From: anna Date: Wed, 27 Oct 2010 20:53:10 +0400 Subject: [PATCH] copyright: avoid velocity exceptions when copyright ends with $ (IDEA-59143) --- .../copyright/pattern/VelocityHelper.java | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/plugins/copyright/src/com/maddyhome/idea/copyright/pattern/VelocityHelper.java b/plugins/copyright/src/com/maddyhome/idea/copyright/pattern/VelocityHelper.java index bbf5ac876213..dc675255df64 100644 --- a/plugins/copyright/src/com/maddyhome/idea/copyright/pattern/VelocityHelper.java +++ b/plugins/copyright/src/com/maddyhome/idea/copyright/pattern/VelocityHelper.java @@ -19,6 +19,7 @@ package com.maddyhome.idea.copyright.pattern; import com.intellij.openapi.application.PathManager; import com.intellij.openapi.module.Module; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.PsiFile; import com.maddyhome.idea.copyright.CopyrightManager; import org.apache.commons.collections.ExtendedProperties; @@ -43,10 +44,15 @@ public class VelocityHelper try { - StringWriter sw = new StringWriter(); - engine.evaluate(vc, sw, CopyrightManager.class.getName(), template); - - return sw.getBuffer().toString(); + StringWriter sw = new StringWriter(); + boolean stripLineBreak = false; + if (template.endsWith("$")) { + template += getVelocitySuffix(); + stripLineBreak = true; + } + engine.evaluate(vc, sw, CopyrightManager.class.getName(), template); + final String result = sw.getBuffer().toString(); + return stripLineBreak ? StringUtil.trimEnd(result, getVelocitySuffix()) : result; } catch (Exception e) { @@ -54,13 +60,20 @@ public class VelocityHelper } } - public static void verify(String text) throws Exception + private static String getVelocitySuffix() { + return "\n"; + } + + public static void verify(String text) throws Exception { VelocityEngine engine = getEngine(); VelocityContext vc = new VelocityContext(); vc.put("today", new DateInfo()); StringWriter sw = new StringWriter(); + if (text.endsWith("$")) { + text += getVelocitySuffix(); + } engine.evaluate(vc, sw, CopyrightManager.class.getName(), text); }