You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by jl...@apache.org on 2016/09/06 16:38:15 UTC

svn commit: r1759457 - in /ofbiz/trunk/framework/webtools: config/webtools.properties src/main/java/org/apache/ofbiz/webtools/labelmanager/LabelReferences.java widget/LabelManagerScreens.xml

Author: jleroux
Date: Tue Sep  6 16:38:14 2016
New Revision: 1759457

URL: http://svn.apache.org/viewvc?rev=1759457&view=rev
Log:
Fixes "The "Only Not Used Labels" option of the Label Manager is broken" OFBIZ-8114

Simply replaces the parenthesis in ServiceUtil.getResource() by 2 spaces when parsing files with getLabelsFromJavaFiles() and getLabelsFromFtlFiles(). 
ServiceUtil.getResource() breaks the parsing
Note: no occurrences of ServiceUtil.getResource() yet in FTL files, and only 16 in Java files.

Also replaces "script" by "minilang" in getLabelsFromSimpleMethodFiles()

This adds a getResourceRegex  in a new webtools.properties files. This property
* Allow to remove this string from files when parsing with Label Manager, else it breaks 
* Moreover the string can't be in the LabelReferences.java file, to avoid side effects

I have also increased the transaction-timeout of the screen "SearchLabels" to 600. 
Because when using the "Only Not Used Labels" option the 1st pass can be long. 10 min should plenty enough, even on old machines. Not blocking anyway, just a bad stack trace in log
I'm sorry you will see a lot of false changes because the LabelManagerScreens.xml had no svn:properties at all, here they are now.


We have 5237 "Not Used Labels". I wondered if they were all real, I just checked some an indeed, they were not used. 
But there are also a huge bunch of *.description.* labels which certainly make sense. I'll remove them from the "Only Not Used Labels" result in another Jira I'll create

Added:
    ofbiz/trunk/framework/webtools/config/webtools.properties   (with props)
Modified:
    ofbiz/trunk/framework/webtools/src/main/java/org/apache/ofbiz/webtools/labelmanager/LabelReferences.java
    ofbiz/trunk/framework/webtools/widget/LabelManagerScreens.xml   (contents, props changed)

Added: ofbiz/trunk/framework/webtools/config/webtools.properties
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webtools/config/webtools.properties?rev=1759457&view=auto
==============================================================================
--- ofbiz/trunk/framework/webtools/config/webtools.properties (added)
+++ ofbiz/trunk/framework/webtools/config/webtools.properties Tue Sep  6 16:38:14 2016
@@ -0,0 +1,22 @@
+###############################################################################
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+###############################################################################
+
+# Allow to remove this string from files when parsing with Label Manager, else it breaks 
+# Moreover the string can't be in the LabelReferences.java file, to avoid side effects
+getResourceRegex = ServiceUtil\\.getResource\\(\\)

Propchange: ofbiz/trunk/framework/webtools/config/webtools.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ofbiz/trunk/framework/webtools/config/webtools.properties
------------------------------------------------------------------------------
    svn:keywords = Date Rev Author URL Id

Propchange: ofbiz/trunk/framework/webtools/config/webtools.properties
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: ofbiz/trunk/framework/webtools/src/main/java/org/apache/ofbiz/webtools/labelmanager/LabelReferences.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webtools/src/main/java/org/apache/ofbiz/webtools/labelmanager/LabelReferences.java?rev=1759457&r1=1759456&r2=1759457&view=diff
==============================================================================
--- ofbiz/trunk/framework/webtools/src/main/java/org/apache/ofbiz/webtools/labelmanager/LabelReferences.java (original)
+++ ofbiz/trunk/framework/webtools/src/main/java/org/apache/ofbiz/webtools/labelmanager/LabelReferences.java Tue Sep  6 16:38:14 2016
@@ -36,6 +36,7 @@ import org.apache.ofbiz.base.component.C
 import org.apache.ofbiz.base.util.Debug;
 import org.apache.ofbiz.base.util.FileUtil;
 import org.apache.ofbiz.base.util.UtilFormatOut;
+import org.apache.ofbiz.base.util.UtilProperties;
 import org.apache.ofbiz.base.util.UtilValidate;
 import org.apache.ofbiz.base.util.UtilXml;
 import org.apache.ofbiz.entity.Delegator;
@@ -59,6 +60,8 @@ public class LabelReferences {
     private static final String uiLabelMap = "uiLabelMap.";
     private static final String formFieldTitle = "FormFieldTitle_";
     private static final String getMessage = "UtilProperties.getMessage(";
+    private static final String getResourceRegex = UtilProperties.getPropertyValue("webtools", "getResourceRegex");
+    private static final String getResource = "ServiceUtil.getResource  ";
 
     protected Map<String, Map<String, Integer>> references = new TreeMap<String, Map<String, Integer>>();
     protected Delegator delegator;
@@ -159,6 +162,7 @@ public class LabelReferences {
             List<File> ftlFiles = FileUtil.findFiles("ftl", rootFolder, null, null);
             for (File file : ftlFiles) {
                 String inFile = FileUtil.readString("UTF-8", file);
+                inFile = inFile.replaceAll(getResourceRegex, getResource);
                 int pos = inFile.indexOf(bracketedUiLabelMap);
                 while (pos >= 0) {
                     int endPos = inFile.indexOf("}", pos);
@@ -182,6 +186,7 @@ public class LabelReferences {
             List<File> javaFiles = FileUtil.findFiles("java", rootFolder + "src", null, null);
             for (File javaFile : javaFiles) {
                 String inFile = FileUtil.readString("UTF-8", javaFile);
+                inFile = inFile.replaceAll(getResourceRegex, getResource);
                 int pos = inFile.indexOf(getMessage);
                 while (pos >= 0) {
                     int endLabel = inFile.indexOf(")", pos);
@@ -247,7 +252,7 @@ public class LabelReferences {
 
     private void getLabelsFromSimpleMethodFiles() throws IOException {
         for (String rootFolder : this.rootFolders) {
-            List<File> simpleMethodsFiles = FileUtil.findFiles("xml", rootFolder + "script", null, null);
+            List<File> simpleMethodsFiles = FileUtil.findFiles("xml", rootFolder + "minilang", null, null);
             for (File file : simpleMethodsFiles) {
                 String inFile = FileUtil.readString("UTF-8", file);
                 findUiLabelMapInFile(inFile, file.getPath());

Modified: ofbiz/trunk/framework/webtools/widget/LabelManagerScreens.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webtools/widget/LabelManagerScreens.xml?rev=1759457&r1=1759456&r2=1759457&view=diff
==============================================================================
--- ofbiz/trunk/framework/webtools/widget/LabelManagerScreens.xml (original)
+++ ofbiz/trunk/framework/webtools/widget/LabelManagerScreens.xml Tue Sep  6 16:38:14 2016
@@ -21,7 +21,7 @@ under the License.
 <screens xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="http://ofbiz.apache.org/Widget-Screen" xsi:schemaLocation="http://ofbiz.apache.org/Widget-Screen http://ofbiz.apache.org/dtds/widget-screen.xsd">
 
-    <screen name="SearchLabels">
+    <screen name="SearchLabels" transaction-timeout="600">
         <section>
             <condition>
                 <if-has-permission permission="LABEL_MANAGER_VIEW"/>

Propchange: ofbiz/trunk/framework/webtools/widget/LabelManagerScreens.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ofbiz/trunk/framework/webtools/widget/LabelManagerScreens.xml
------------------------------------------------------------------------------
    svn:keywords = "Date Rev Author URL Id"

Propchange: ofbiz/trunk/framework/webtools/widget/LabelManagerScreens.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml



Re: svn commit: r1759457 - in /ofbiz/trunk/framework/webtools: config/webtools.properties src/main/java/org/apache/ofbiz/webtools/labelmanager/LabelReferences.java widget/LabelManagerScreens.xml

Posted by Jacques Le Roux <ja...@les7arts.com>.
OK no problems with me, I'll change that. I must say I did no like the property either.

Jacques


Le 07/09/2016 � 09:56, Jacopo Cappellato a �crit :
> On Wed, Sep 7, 2016 at 9:23 AM, Jacques Le Roux <
> jacques.le.roux@les7arts.com> wrote:
>
>> ...
>>
> 2. So I created a private static final String: private static final String
>> getResourceRegex = "ServiceUtil\\.getResource\\(\\)"
>>     But this did not work. I got
>>
>>     2016-09-07 08:27:32,489 |ttp-nio-8443-exec-10 |ScriptUtil
>>        |W| Error running script at location
>>     [component://webtools/groovyScripts/labelmanager/LabelManager.groovy]:
>> java.lang.ArrayIndexOutOfBoundsException: 1
>>     java.lang.ArrayIndexOutOfBoundsException: 1  at
>>     org.apache.ofbiz.webtools.labelmanager.LabelReferences.getL
>> abelsFromJavaFiles(LabelReferences.java:196) ~[ofbiz.jar:?]
>>
>>
> Without further digging into this issue, I would prefer the following tweak:
>
> 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
> 1759552)
> +++
> framework/webtools/src/main/java/org/apache/ofbiz/webtools/labelmanager/LabelReferences.java
> (working
> copy)
> @@ -60,7 +60,7 @@
>       private static final String uiLabelMap = "uiLabelMap.";
>       private static final String formFieldTitle = "FormFieldTitle_";
>       private static final String getMessage = "UtilProperties.getMessage(";
> -    private static final String getResourceRegex =
> UtilProperties.getPropertyValue("webtools", "getResourceRegex");
> +    private static final String getResourceRegex =
> "ServiceUtil\\.getResource\\(\\)";
>       private static final String getResource = "ServiceUtil.getResource  ";
>
>       protected Map<String, Map<String, Integer>> references = new
> TreeMap<String, Map<String, Integer>>();
> @@ -185,6 +185,8 @@
>           for (String rootFolder : this.rootFolders) {
>               List<File> javaFiles = FileUtil.findFiles("java", rootFolder +
> "src", null, null);
>               for (File javaFile : javaFiles) {
> +                // do not parse this file
> +                if ("LabelReferences.java".equals(javaFile.getName()))
> continue;
>                   String inFile = FileUtil.readString("UTF-8", javaFile);
>                   inFile = inFile.replaceAll(getResourceRegex, getResource);
>                   int pos = inFile.indexOf(getMessage);
>
>
> In this way, we will not need an additional configuration file and the
> ugliness will be self contained in the LabelReference class.
>
> Jacopo
>


Re: svn commit: r1759457 - in /ofbiz/trunk/framework/webtools: config/webtools.properties src/main/java/org/apache/ofbiz/webtools/labelmanager/LabelReferences.java widget/LabelManagerScreens.xml

Posted by Jacopo Cappellato <ja...@hotwaxsystems.com>.
On Wed, Sep 7, 2016 at 9:23 AM, Jacques Le Roux <
jacques.le.roux@les7arts.com> wrote:

> ...
>
2. So I created a private static final String: private static final String
> getResourceRegex = "ServiceUtil\\.getResource\\(\\)"
>    But this did not work. I got
>
>    2016-09-07 08:27:32,489 |ttp-nio-8443-exec-10 |ScriptUtil
>       |W| Error running script at location
>    [component://webtools/groovyScripts/labelmanager/LabelManager.groovy]:
> java.lang.ArrayIndexOutOfBoundsException: 1
>    java.lang.ArrayIndexOutOfBoundsException: 1  at
>    org.apache.ofbiz.webtools.labelmanager.LabelReferences.getL
> abelsFromJavaFiles(LabelReferences.java:196) ~[ofbiz.jar:?]
>
>
Without further digging into this issue, I would prefer the following tweak:

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
1759552)
+++
framework/webtools/src/main/java/org/apache/ofbiz/webtools/labelmanager/LabelReferences.java
(working
copy)
@@ -60,7 +60,7 @@
     private static final String uiLabelMap = "uiLabelMap.";
     private static final String formFieldTitle = "FormFieldTitle_";
     private static final String getMessage = "UtilProperties.getMessage(";
-    private static final String getResourceRegex =
UtilProperties.getPropertyValue("webtools", "getResourceRegex");
+    private static final String getResourceRegex =
"ServiceUtil\\.getResource\\(\\)";
     private static final String getResource = "ServiceUtil.getResource  ";

     protected Map<String, Map<String, Integer>> references = new
TreeMap<String, Map<String, Integer>>();
@@ -185,6 +185,8 @@
         for (String rootFolder : this.rootFolders) {
             List<File> javaFiles = FileUtil.findFiles("java", rootFolder +
"src", null, null);
             for (File javaFile : javaFiles) {
+                // do not parse this file
+                if ("LabelReferences.java".equals(javaFile.getName()))
continue;
                 String inFile = FileUtil.readString("UTF-8", javaFile);
                 inFile = inFile.replaceAll(getResourceRegex, getResource);
                 int pos = inFile.indexOf(getMessage);


In this way, we will not need an additional configuration file and the
ugliness will be self contained in the LabelReference class.

Jacopo

Re: svn commit: r1759457 - in /ofbiz/trunk/framework/webtools: config/webtools.properties src/main/java/org/apache/ofbiz/webtools/labelmanager/LabelReferences.java widget/LabelManagerScreens.xml

Posted by Jacques Le Roux <ja...@les7arts.com>.
Le 06/09/2016 � 19:03, Jacopo Cappellato a �crit :
> On Tue, Sep 6, 2016 at 6:38 PM, <jl...@apache.org> wrote:
>
>> Author: jleroux
>> Date: Tue Sep  6 16:38:14 2016
>> New Revision: 1759457
>>
>> URL: http://svn.apache.org/viewvc?rev=1759457&view=rev
>> Log:
>>
> ...
>
>> * Moreover the string can't be in the LabelReferences.java file, to avoid
>> side effects
>>
> Hi Jacques,
>
> what are the side effects?
>
> Thanks,
>
> Jacopo
>
Hi Jacopo,

Good question, it has tortured me a moment, please try yourself you will see (kidding, see below ;))

I initially thought about 2 places to put the replacing regexp string:

 1. I began directly in code to test: inFile = inFile.replaceAll("ServiceUtil\\.getResource\\(\\)", getResource);
    This worked, and I decided to follow the pattern already used: a private member
 2. So I created a private static final String: private static final String getResourceRegex = "ServiceUtil\\.getResource\\(\\)"
    But this did not work. I got

    2016-09-07 08:27:32,489 |ttp-nio-8443-exec-10 |ScriptUtil                    |W| Error running script at location
    [component://webtools/groovyScripts/labelmanager/LabelManager.groovy]: java.lang.ArrayIndexOutOfBoundsException: 1
    java.lang.ArrayIndexOutOfBoundsException: 1  at
    org.apache.ofbiz.webtools.labelmanager.LabelReferences.getLabelsFromJavaFiles(LabelReferences.java:196) ~[ofbiz.jar:?]

    I wondered about doubling backslashes (which made not sense but with Java regexp and backslashes ...), when doing got the same error. And by
    investigating I found that using a member had a side effect during the parsing.
    If you use

                                 if (args.length > 1) {
                                     if (searchString.equals(args[1].trim())) {
                                         setLabelReference(labelKey, javaFile.getPath());
                                     }
                                 } else {
                                     Debug.log("searchString = " + searchString);
                                     Debug.log("args[0] = " + args[0]);
                                 }
    You will see the culprit:

    2016-09-07 09:17:32,873 |http-nio-8443-exec-7 |LabelManagerFactory           |I| Current file : AccountingEntityLabels.xml
    2016-09-07 09:17:33,903 |http-nio-8443-exec-7 |NoModule                      |F| searchString = "InvoiceItemType.description.PITM_DISCOUNT_ADJ"
    2016-09-07 09:17:33,903 |http-nio-8443-exec-7 |NoModule                      |F| args[0] = ";
         private static final String getResourceRegex = "ServiceUtil\\.getResource\\(\\

    That's also how I discovered we are considering entity description labels as not used when they are automatically by widget and even overriding
    some in data files
    BTW there are sometimes better English labels descriptions in data files. They should be used in labels and translations, 2 Jiras to create...

HTH

Jacques


Re: svn commit: r1759457 - in /ofbiz/trunk/framework/webtools: config/webtools.properties src/main/java/org/apache/ofbiz/webtools/labelmanager/LabelReferences.java widget/LabelManagerScreens.xml

Posted by Jacopo Cappellato <ja...@hotwaxsystems.com>.
On Tue, Sep 6, 2016 at 6:38 PM, <jl...@apache.org> wrote:

> Author: jleroux
> Date: Tue Sep  6 16:38:14 2016
> New Revision: 1759457
>
> URL: http://svn.apache.org/viewvc?rev=1759457&view=rev
> Log:
>
...

> * Moreover the string can't be in the LabelReferences.java file, to avoid
> side effects
>

Hi Jacques,

what are the side effects?

Thanks,

Jacopo