[jira] [Commented] (OFBIZ-8153) LabelManager doesn't search .groovy files

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[jira] [Commented] (OFBIZ-8153) LabelManager doesn't search .groovy files

Nicolas Malin (Jira)

    [ https://issues.apache.org/jira/browse/OFBIZ-8153?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15471632#comment-15471632 ]

Jacques Le Roux commented on OFBIZ-8153:
----------------------------------------

HI Pierre,

Could you please try the following patch. I did not put much brain it it, it's just a copy of the Java one, I did not test...
{code}
Index: framework/webtools/src/main/java/org/apache/ofbiz/webtools/labelmanager/LabelReferences.java
===================================================================
--- framework/webtools/src/main/java/org/apache/ofbiz/webtools/labelmanager/LabelReferences.java (revision 1759573)
+++ framework/webtools/src/main/java/org/apache/ofbiz/webtools/labelmanager/LabelReferences.java (working copy)
@@ -109,8 +109,10 @@
         }
         // get labels from FTL files
         getLabelsFromFtlFiles();
-        // get labels from java files
+        // get labels from Java files
         getLabelsFromJavaFiles();
+        // get labels from Groovy files
+        getLabelsFromGroovyFiles();
         // get labels from simple method files
         getLabelsFromSimpleMethodFiles();
         // get labels from widgets files
@@ -209,6 +211,33 @@
         }
     }
 
+    private void getLabelsFromGroovyFiles() throws IOException {
+        for (String rootFolder : this.rootFolders) {
+            List<File> groovyFiles = FileUtil.findFiles("groovy", rootFolder + "groovyScripts", null, null);
+            for (File groovyFile : groovyFiles) {
+                String inFile = FileUtil.readString("UTF-8", groovyFile);
+                inFile = inFile.replaceAll(getResourceRegex, getResource);
+                int pos = inFile.indexOf(getMessage);
+                while (pos >= 0) {
+                    int endLabel = inFile.indexOf(")", pos);
+                    if (endLabel >= 0) {
+                        String[] args = inFile.substring(pos + getMessage.length(), endLabel).split(",");
+                        for (String labelKey : this.labelSet) {
+                            String searchString = "\"" + labelKey + "\"";
+                            if (searchString.equals(args[1].trim())) {
+                                setLabelReference(labelKey, groovyFile.getPath());
+                            }
+                        }
+                        pos = endLabel;
+                    } else {
+                        pos = pos + getMessage.length();
+                    }
+                    pos = inFile.indexOf(getMessage, pos);
+                }
+            }
+        }
+    }
+
     protected void findUiLabelMapInFile(String inFile, String filePath) {
         int pos = inFile.indexOf(uiLabelMap);
         while (pos >= 0) {
{code}

> LabelManager doesn't search .groovy files
> -----------------------------------------
>
>                 Key: OFBIZ-8153
>                 URL: https://issues.apache.org/jira/browse/OFBIZ-8153
>             Project: OFBiz
>          Issue Type: Bug
>          Components: framework/webtools
>    Affects Versions: Release Branch 14.12, Trunk, Release Branch 15.12
>            Reporter: Pierre Smits
>            Assignee: Jacques Le Roux
>
> There are over 60 labels used in groovy files. These don't get reflected in the counts of the label manager and in the search for labels not used.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)