Author: henning
Date: Tue Sep 27 03:10:50 2005
New Revision: 291890

URL: http://svn.apache.org/viewcvs?rev=291890&view=rev
Log:
Remove some findbugs issues, including a number of System.exit()
calls.


Modified:
    
jakarta/velocity/core/trunk/src/java/org/apache/velocity/convert/WebMacro.java

Modified: 
jakarta/velocity/core/trunk/src/java/org/apache/velocity/convert/WebMacro.java
URL: 
http://svn.apache.org/viewcvs/jakarta/velocity/core/trunk/src/java/org/apache/velocity/convert/WebMacro.java?rev=291890&r1=291889&r2=291890&view=diff
==============================================================================
--- 
jakarta/velocity/core/trunk/src/java/org/apache/velocity/convert/WebMacro.java 
(original)
+++ 
jakarta/velocity/core/trunk/src/java/org/apache/velocity/convert/WebMacro.java 
Tue Sep 27 03:10:50 2005
@@ -18,6 +18,7 @@
 
 import java.io.File;
 import java.io.FileWriter;
+import java.io.IOException;
 
 import org.apache.oro.text.perl.Perl5Util;
 import org.apache.velocity.util.StringUtils;
@@ -112,9 +113,7 @@
         
         if (!file.exists())
         {
-            System.err.println
-                ("The specified template or directory does not exist");
-            System.exit(1);
+            throw new RuntimeException("The specified template or directory 
does not exist");
         }
         
         if (file.isDirectory())
@@ -153,18 +152,12 @@
     
         System.out.println("Converting " + file + "...");
         
-        String template;
-        String templateDir;
-        String newTemplate;
+        String template = file;
+        String templateDir = "";
+        String newTemplate = convertName(file);
         File outputDirectory;
         
-        if (basedir.length() == 0)
-        {
-            template = file;
-            templateDir = "";
-            newTemplate = convertName(file);
-        }            
-        else
+        if (basedir.length() > 0)
         {
             template = basedir + File.separator + file;
             templateDir = newBasedir + extractPath(file);
@@ -180,17 +173,31 @@
         }            
         
         String convertedTemplate = convertTemplate(template);
-                    
+
+        FileWriter fw = null;
         try
         {
-            FileWriter fw = new FileWriter(newTemplate);
+            fw = new FileWriter(newTemplate);
             fw.write(convertedTemplate);
-            fw.close();
         }
         catch (Exception e)
         {
             e.printStackTrace();
         }
+        finally
+        {
+            if (fw != null)
+            {
+                try
+                {
+                    fw.close();
+                }
+                catch (IOException io)
+                {
+                    // Do nothing
+                }
+            }
+        }
     
         return true;
     }
@@ -211,14 +218,9 @@
      */
     private String convertName(String name)
     {
-        if (name.indexOf(WM_EXT) > 0)
-        {
-            return name.substring(0, name.indexOf(WM_EXT)) + VM_EXT;
-        }
-        else
-        {
-            return name;
-        }
+        return (name.indexOf(WM_EXT) < 0) 
+                ? name 
+                : name.substring(0, name.indexOf(WM_EXT)) + VM_EXT;
     }
 
     /**
@@ -227,7 +229,6 @@
     private static final void usage()
     {
         System.err.println("Usage: convert-wm <template.wm | directory>");
-        System.exit(1);
     }
 
     /**



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

Reply via email to