mail[Wesnoth-commits] r44014 - in /trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin: utils/StringUtils.java wizards/TemplateProvider.java


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by timotei_cluj on July 09, 2010 - 00:06:
Author: timotei
Date: Fri Jul  9 00:06:28 2010
New Revision: 44014

URL: http://svn.gna.org/viewcvs/wesnoth?rev=44014&view=rev
Log:
eclipse plugin: remove empty lines in the resulting file

Modified:
    
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/utils/StringUtils.java
    
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/TemplateProvider.java

Modified: 
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/utils/StringUtils.java
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/utils/StringUtils.java?rev=44014&r1=44013&r2=44014&view=diff
==============================================================================
--- 
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/utils/StringUtils.java
 (original)
+++ 
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/utils/StringUtils.java
 Fri Jul  9 00:06:28 2010
@@ -72,8 +72,8 @@
         * @param removeTrailing removes or not the preceding 'character' 
characters
         * @return
         */
-       public static String
-                       removeIncorrectCharacters(String target, char 
character, boolean removeTrailing, boolean removePreceding)
+       public static String removeIncorrectCharacters(String target, char 
character,
+                       boolean removeTrailing, boolean removePreceding)
        {
                StringBuilder resString = new StringBuilder();
 
@@ -86,7 +86,8 @@
                                continue;
                        }
 
-                       if (target.charAt(i) == character && ((removeTrailing 
&& i == target.length()) || (removePreceding && i == 0)))
+                       if (target.charAt(i) == character &&
+                                       ((removeTrailing && i == 
target.length()) || (removePreceding && i == 0)))
                        {
                                continue;
                        }
@@ -152,7 +153,7 @@
        {
                // get the current indentation
                Pattern pattern = Pattern.compile("[\t ]*");
-               Matcher matcher = pattern.matcher(source);
+               Matcher matcher = pattern.matcher(string);
                String indent = "";
                if (matcher.find())
                {

Modified: 
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/TemplateProvider.java
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/TemplateProvider.java?rev=44014&r1=44013&r2=44014&view=diff
==============================================================================
--- 
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/TemplateProvider.java
 (original)
+++ 
trunk/utils/java/eclipse_plugin/src/wesnoth_eclipse_plugin/wizards/TemplateProvider.java
 Fri Jul  9 00:06:28 2010
@@ -9,6 +9,8 @@
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import wesnoth_eclipse_plugin.Logger;
 import wesnoth_eclipse_plugin.utils.Pair;
@@ -43,7 +45,9 @@
                        Logger.print("reading templates...");
 
                        Logger.print(pluginFullPath_ + templatesFile);
-                       BufferedReader reader = new BufferedReader(new 
FileReader(getClass().getProtectionDomain().getCodeSource().getLocation().getPath()
 + templatesFile));
+                       BufferedReader reader =
+                                       new BufferedReader(new 
FileReader(getClass().getProtectionDomain().getCodeSource().getLocation().getPath()
+                                                       + templatesFile));
                        BufferedReader tmpReader;
                        String line, tmpLine, content;
 
@@ -93,30 +97,39 @@
 
                String result = "";
                String[] template = StringUtils.getLines(tmpTemplate);
+               boolean skipLine;
 
                for (int i = 0; i < template.length; ++i)
                {
-
+                       skipLine = false;
                        for (ReplaceableParameter param : parameters)
                        {
                                if (template[i].contains(param.paramName))
                                {
-                                       template[i] = 
template[i].replace(param.paramName, param.paramValue);
+                                       template[i] = 
StringUtils.replaceWithIndent(template[i], param.paramName, param.paramValue);
 
                                        if (!templateName.equals("build_xml") 
&& (param.paramValue == null || param.paramValue.isEmpty()))
                                        {
                                                // we don't have any value 
supplied -
-                                               // let's comment that line 
(if it's not already
-                                               // commented)
+                                               // let's comment that line 
(if it's not already commented)
+                                               // or remove it if it's empty
                                                if 
(!(StringUtils.startsWith(template[i], "#")))
                                                {
                                                        template[i] = "#" + 
template[i];
+                                                       Pattern pattern = 
Pattern.compile("#[\t ]*");
+                                                       Matcher matcher = 
pattern.matcher(template[i]);
+                                                       if (matcher.matches())
+                                                       {
+                                                               skipLine = 
true;
+                                                               
System.out.println("Skipping line");
+                                                       }
                                                }
                                        }
                                }
                        }
 
-                       result += template[i] + "\n";
+                       if (skipLine == false)
+                               result += template[i] + "\n";
                }
                return result;
        }




Related Messages


Powered by MHonArc, Updated Fri Jul 09 00:20:08 2010