Details

    • Type: Sub-task
    • Status: Closed
    • Priority: Minor
    • Resolution: Implemented
    • Affects Version/s: Trunk
    • Fix Version/s: 16.11.01
    • Component/s: framework
    • Labels:

      Description

      Currently the iterateOverActiveComponents function or tasks exists both in build.gradle and settings.gradle.

      Do we need both? Which one is superfluous?

      1. OFBIZ-7749.patch
        5 kB
        Michael Brohl

        Activity

        Hide
        taher Taher Alkhateeb added a comment -

        Yes we need both, one for declaring subprojects and one for other custom logic. The code cannot be shared between both files because each one is visible in a different stage (one in the initialization stage of gradle and the other one during the configuration & execution phases).

        Hence this JIRA is unnecessary

        Show
        taher Taher Alkhateeb added a comment - Yes we need both, one for declaring subprojects and one for other custom logic. The code cannot be shared between both files because each one is visible in a different stage (one in the initialization stage of gradle and the other one during the configuration & execution phases). Hence this JIRA is unnecessary
        Hide
        pfm.smits Pierre Smits added a comment -

        If the code for iterateOverActiveComponents is different between declaring sub projects and other custom logic, I suggest to use different names to avoid confusion.

        Remember DRY.

        Show
        pfm.smits Pierre Smits added a comment - If the code for iterateOverActiveComponents is different between declaring sub projects and other custom logic, I suggest to use different names to avoid confusion. Remember DRY.
        Hide
        jacques.le.roux Jacques Le Roux added a comment -

        Taher created a reusable parametrized block of code named iterateOverActiveComponents (a function in Groovy jargon) and you want to duplicate it?

        Without answers I'll close this issue today.

        Show
        jacques.le.roux Jacques Le Roux added a comment - Taher created a reusable parametrized block of code named iterateOverActiveComponents (a function in Groovy jargon) and you want to duplicate it? Without answers I'll close this issue today.
        Hide
        pfm.smits Pierre Smits added a comment -

        Closed under a false pretence. Reopening.

        Show
        pfm.smits Pierre Smits added a comment - Closed under a false pretence. Reopening.
        Hide
        pfm.smits Pierre Smits added a comment -

        Taher created the duplicate code. Before jumping to conclusions I suggest you read all first.

        in build.gradle:

        def iterateOverActiveComponents(applyFunction) {
            def frameworkComponents = new XmlParser().parse('framework/component-load.xml')
            def applicationsComponents = new XmlParser().parse('applications/component-load.xml')
            def specialpurposeComponents = new XmlParser().parse('specialpurpose/component-load.xml')
        
            applyFunction file('framework/start')
        
            frameworkComponents.children().each { component ->
                applyFunction file("framework/"+component.@"component-location")
            }
            applicationsComponents.children().each { component ->
                applyFunction file("applications/"+component.@"component-location")
            }
            specialpurposeComponents.children().each { component ->
                applyFunction file("specialpurpose/"+component.@"component-location")
            }
        
            file('hot-deploy').eachDir { component ->
                applyFunction(component)
            }
        }
        

        and in settings.gradle:

        def iterateOverActiveComponents(applyFunction) {
            def frameworkComponents = new XmlParser().parse('framework/component-load.xml')
            def applicationsComponents = new XmlParser().parse('applications/component-load.xml')
            def specialpurposeComponents = new XmlParser().parse('specialpurpose/component-load.xml')
        
            applyFunction file('framework/start')
        
            frameworkComponents.children().each { component ->
                applyFunction file("framework/"+component.@"component-location")
            }
            applicationsComponents.children().each { component ->
                applyFunction file("applications/"+component.@"component-location")
            }
            specialpurposeComponents.children().each { component ->
                applyFunction file("specialpurpose/"+component.@"component-location")
            }
        
            file('hot-deploy').eachDir { component ->
                applyFunction(component)
            }
        }
        
        Show
        pfm.smits Pierre Smits added a comment - Taher created the duplicate code. Before jumping to conclusions I suggest you read all first. in build.gradle : def iterateOverActiveComponents(applyFunction) { def frameworkComponents = new XmlParser().parse('framework/component-load.xml') def applicationsComponents = new XmlParser().parse('applications/component-load.xml') def specialpurposeComponents = new XmlParser().parse('specialpurpose/component-load.xml') applyFunction file('framework/start') frameworkComponents.children().each { component -> applyFunction file( "framework/" +component.@ "component-location" ) } applicationsComponents.children().each { component -> applyFunction file( "applications/" +component.@ "component-location" ) } specialpurposeComponents.children().each { component -> applyFunction file( "specialpurpose/" +component.@ "component-location" ) } file('hot-deploy').eachDir { component -> applyFunction(component) } } and in settings.gradle : def iterateOverActiveComponents(applyFunction) { def frameworkComponents = new XmlParser().parse('framework/component-load.xml') def applicationsComponents = new XmlParser().parse('applications/component-load.xml') def specialpurposeComponents = new XmlParser().parse('specialpurpose/component-load.xml') applyFunction file('framework/start') frameworkComponents.children().each { component -> applyFunction file( "framework/" +component.@ "component-location" ) } applicationsComponents.children().each { component -> applyFunction file( "applications/" +component.@ "component-location" ) } specialpurposeComponents.children().each { component -> applyFunction file( "specialpurpose/" +component.@ "component-location" ) } file('hot-deploy').eachDir { component -> applyFunction(component) } }
        Hide
        jacques.le.roux Jacques Le Roux added a comment -

        Pierre,

        Did you review the code? What do you want exactly, it's not clear to me :-o ?

        Show
        jacques.le.roux Jacques Le Roux added a comment - Pierre, Did you review the code? What do you want exactly, it's not clear to me :-o ?
        Hide
        jacques.le.roux Jacques Le Roux added a comment -

        Ah, I read the description too fast. I though it was only about the build.gradle file. I think Taher answered already

        The code cannot be shared between both files because each one is visible in a different stage (one in the initialization stage of gradle and the other one during the configuration & execution phases).

        Please provide a patch for better code if you can, but don't let this issue open indefinitely...

        Show
        jacques.le.roux Jacques Le Roux added a comment - Ah, I read the description too fast. I though it was only about the build.gradle file. I think Taher answered already The code cannot be shared between both files because each one is visible in a different stage (one in the initialization stage of gradle and the other one during the configuration & execution phases). Please provide a patch for better code if you can, but don't let this issue open indefinitely...
        Hide
        jacques.le.roux Jacques Le Roux added a comment -

        For readers, see my comment above...

        Show
        jacques.le.roux Jacques Le Roux added a comment - For readers, see my comment above...
        Hide
        pfm.smits Pierre Smits added a comment -

        Yes I did - 5 days ago - and I couldn't find the difference.

        Show
        pfm.smits Pierre Smits added a comment - Yes I did - 5 days ago - and I couldn't find the difference.
        Hide
        taher Taher Alkhateeb added a comment -

        Hi Pierre,

        In reply to your comments:

        The two functions are exactly the same and that is why they have the same name. They do exactly the same thing, but we cannot write them only once (or maybe we there is a workaround in that I'm unaware of yet, feel free to help us).

        The reason why we cannot is that Gradle runs in three stages, Initialization, Configuration, and Execution. The initialization stage is different from the other stages and cannot reuse code. So build.gradle is not visible to settings.gradle and vice-versa because they are parsed in different time-lines.

        In most projects this does not happen, but because of the complexity and non-standard directory structure in OFBiz, we needed that same bit of code in both the initialization phase (to create the subprojects) and in the other phases for everything else.

        I hope this answers your inquiries.

        Show
        taher Taher Alkhateeb added a comment - Hi Pierre, In reply to your comments: The two functions are exactly the same and that is why they have the same name. They do exactly the same thing, but we cannot write them only once (or maybe we there is a workaround in that I'm unaware of yet, feel free to help us). The reason why we cannot is that Gradle runs in three stages, Initialization, Configuration, and Execution. The initialization stage is different from the other stages and cannot reuse code. So build.gradle is not visible to settings.gradle and vice-versa because they are parsed in different time-lines. In most projects this does not happen, but because of the complexity and non-standard directory structure in OFBiz, we needed that same bit of code in both the initialization phase (to create the subprojects) and in the other phases for everything else. I hope this answers your inquiries.
        Hide
        jacques.le.roux Jacques Le Roux added a comment -

        Hi Pierre, if you agree please close. Of course, if you prefer to take some time to do some researches please take this time.

        Show
        jacques.le.roux Jacques Le Roux added a comment - Hi Pierre, if you agree please close. Of course, if you prefer to take some time to do some researches please take this time.
        Hide
        mbrohl Michael Brohl added a comment -

        This patch introduces a new gradle file which holds the shared method iterateOverActiveComponents which is used by build.gradle and settings.gradle.

        Thanks Pierre for the trigger to learn some Gradle stuff

        Show
        mbrohl Michael Brohl added a comment - This patch introduces a new gradle file which holds the shared method iterateOverActiveComponents which is used by build.gradle and settings.gradle. Thanks Pierre for the trigger to learn some Gradle stuff
        Hide
        taher Taher Alkhateeb added a comment -

        Fantastic Michael. if all tests pass then please go ahead and commit this. I suggest in line with the old names we used you can call it common.gradle instead.

        Show
        taher Taher Alkhateeb added a comment - Fantastic Michael. if all tests pass then please go ahead and commit this. I suggest in line with the old names we used you can call it common.gradle instead.
        Hide
        jacques.le.roux Jacques Le Roux added a comment - - edited

        Thanks Michael,

        Your patch is in trunk at revision: 1752890

        All tests pass.

        For the sake of history and especially the link Michael provided, Michael asked me yesterday on HipChat:

        have you tried this: https://docs.gradle.org/current/userguide/userguide_single.html#sec%3aconfiguring_using_external_scr... in reference to OFBIZ-7749

        I replied

        No I did not try that. Is it new with 2.14 (we use 2.13 because 2.14 is not released yet, right?)

        Found this https://discuss.gradle.org/t/how-do-i-include-buildscript-block-from-external-gradle-script/7016/7

        I checked this morning, thanks to the Gradle wrapper we use 2.14 which was released on 14th June 2016: https://gradle.org/gradle-download/ The Gradle wrapper is a bliss

        Show
        jacques.le.roux Jacques Le Roux added a comment - - edited Thanks Michael, Your patch is in trunk at revision: 1752890 All tests pass. For the sake of history and especially the link Michael provided, Michael asked me yesterday on HipChat: have you tried this: https://docs.gradle.org/current/userguide/userguide_single.html#sec%3aconfiguring_using_external_scr ... in reference to OFBIZ-7749 I replied No I did not try that. Is it new with 2.14 (we use 2.13 because 2.14 is not released yet, right?) Found this https://discuss.gradle.org/t/how-do-i-include-buildscript-block-from-external-gradle-script/7016/7 I checked this morning, thanks to the Gradle wrapper we use 2.14 which was released on 14th June 2016: https://gradle.org/gradle-download/ The Gradle wrapper is a bliss

          People

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

            Dates

            • Created:
              Updated:
              Resolved:

              Development