Uploaded image for project: 'OFBiz'
  1. OFBiz
  2. OFBIZ-8153

LabelManager doesn't search .groovy files

    Details

      Description

      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.

        Activity

        Hide
        jacques.le.roux Jacques Le Roux added a comment -

        HI Pierre, I assigned myself because I have already decided to work on OFBIZ-8154 . But let me know if you expect to work on this issue, and then please assign yourself. Thanks.

        Show
        jacques.le.roux Jacques Le Roux added a comment - HI Pierre, I assigned myself because I have already decided to work on OFBIZ-8154 . But let me know if you expect to work on this issue, and then please assign yourself. Thanks.
        Hide
        pfm.smits Pierre Smits added a comment -

        Hi Jacques Le Roux,

        No worries and thanks. If I was planning on working on this I would have assigned myself.

        Show
        pfm.smits Pierre Smits added a comment - Hi Jacques Le Roux , No worries and thanks. If I was planning on working on this I would have assigned myself.
        Hide
        jacques.le.roux Jacques Le Roux added a comment -

        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...

        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) {
        
        Show
        jacques.le.roux Jacques Le Roux added a comment - 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... 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) {
        Hide
        pfm.smits Pierre Smits added a comment -

        Hi Jacques,

        It still seem to forgo on the issues in groovy files. I tested it against various labels in BalanceSheet.groovy in the accounting component. It didn't recognise:

        • uiLabelMap.AccountingTotalAssets
        • uiLabelMap.AccountingTotalAccumulatedDepreciation

        etc.

        Show
        pfm.smits Pierre Smits added a comment - Hi Jacques, It still seem to forgo on the issues in groovy files. I tested it against various labels in BalanceSheet.groovy in the accounting component. It didn't recognise: uiLabelMap.AccountingTotalAssets uiLabelMap.AccountingTotalAccumulatedDepreciation etc.
        Hide
        jacques.le.roux Jacques Le Roux added a comment -

        Thanks Pierre, I'll double check that

        Show
        jacques.le.roux Jacques Le Roux added a comment - Thanks Pierre, I'll double check that
        Hide
        jacques.le.roux Jacques Le Roux added a comment -

        Thanks for report Pierre,

        I committed a fix in
        trunk r1759941
        R15.12, R14.12, R13.07 r1759942

        My previous patch was non sense, this commit uses the already existing findUiLabelMapInFile so should do the work rightly.

        Show
        jacques.le.roux Jacques Le Roux added a comment - Thanks for report Pierre, I committed a fix in trunk r1759941 R15.12, R14.12, R13.07 r1759942 My previous patch was non sense, this commit uses the already existing findUiLabelMapInFile so should do the work rightly.

          People

          • Assignee:
            jacques.le.roux Jacques Le Roux
            Reporter:
            pfm.smits Pierre Smits
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development