Improved: fully refactored the component loading logic in Gradle
(OFBIZ-9182)

This commit provides the following:
- Fully refactor common.gradle so that it mirrors the component loading
  logic found in ComponentContainer. This makes the loading very flexible
  and changing the directory structure should have no impact on the build
  scripts.
- Gradle will now ignore a component if it exists but disabled in
  ofbiz-component.xml (i.e. enabled="false")
- Removes /plugins/component-load.xml
- Disables the ebaystore component in ofbiz-component.xml

The above is needed as a first step toward preparing the project for svn
restructure


git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@1780790 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/common.gradle b/common.gradle
index 4c4e936..326929c 100644
--- a/common.gradle
+++ b/common.gradle
@@ -17,27 +17,37 @@
  * under the License.
  */
 def iterateOverActiveComponents(applyFunction) {
-    def frameworkComponents = new XmlParser().parse("${rootDir}/framework/component-load.xml")
-    def applicationsComponents = new XmlParser().parse("${rootDir}/applications/component-load.xml")
-    def pluginsComponents = new XmlParser().parse("${rootDir}/plugins/component-load.xml")
 
+    // Start is not a real component, therefore loading it manually
     applyFunction file("${rootDir}/framework/start")
 
-    frameworkComponents.children().each { component ->
-        applyFunction file("${rootDir}/framework/"+component.@"component-location")
-    }
-    applicationsComponents.children().each { component ->
-        applyFunction file("${rootDir}/applications/"+component.@"component-location")
-    }
-    pluginsComponents.children().each { component ->
-        applyFunction file("${rootDir}/plugins/"+component.@"component-location")
-    }
+    def rootComponents = new XmlParser().parse("${rootDir}/framework/base/config/component-load.xml")
+    rootComponents.children().each { rootComponent ->
+        File componentLoadFile = file "${rootDir}/"+ rootComponent.@"parent-directory" + "/component-load.xml"
 
-    file("${rootDir}/themes").eachDir { component ->
-        applyFunction(component)
+        if(componentLoadFile.exists()) {
+            // iterate through the components defined in component-load.xml
+            def parsedComponents = new XmlParser().parse(componentLoadFile.toString())
+            parsedComponents.children().each { component ->
+                def componentLocation = file "${rootDir}/"+ rootComponent.@"parent-directory" + '/' + component.@"component-location"
+                applyIfEnabled(componentLocation, applyFunction)
+            }
+        } else {
+            // iterate through all components (subdirectories of the root component)
+            file(rootComponent.@"parent-directory").eachDir { componentLocation ->
+                applyIfEnabled(componentLocation, applyFunction)
+            }
+        }
     }
-    file("${rootDir}/hot-deploy").eachDir { component ->
-        applyFunction(component)
+}
+
+def applyIfEnabled(componentDir, applyFunction) {
+    File componentFile = file componentDir.toString() + '/ofbiz-component.xml'
+    if(componentFile.exists()) {
+        def parsedComponent = new XmlParser().parse(componentFile.toString())
+        if(parsedComponent.@enabled == null || parsedComponent.@enabled == "true") {
+            applyFunction componentDir
+        }
     }
 }
 
diff --git a/plugins/component-load.xml b/plugins/component-load.xml
deleted file mode 100644
index 899a3a7..0000000
--- a/plugins/component-load.xml
+++ /dev/null
@@ -1,44 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-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.
--->
-
-<component-loader xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-        xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/component-loader.xsd">
-    <load-component component-location="lucene"/>
-    <load-component component-location="solr"/>
-    <load-component component-location="ecommerce"/>
-    <load-component component-location="hhfacility"/>
-    <load-component component-location="assetmaint"/>
-    <load-component component-location="cmssite"/>
-    <load-component component-location="projectmgr"/>
-    <load-component component-location="scrum"/>
-    <load-component component-location="ebay"/>
-    <!--
-    <load-component component-location="ebaystore"/>
-    -->
-    <load-component component-location="myportal"/>
-    <load-component component-location="ldap"/>
-    <load-component component-location="webpos"/>
-    <load-component component-location="birt"/>
-    <load-component component-location="bi"/>
-    <load-component component-location="example"/>
-    <load-component component-location="exampleext"/>
-    <load-component component-location="passport"/>
-    <load-component component-location="pricat"/>
-</component-loader>
diff --git a/plugins/ebaystore/ofbiz-component.xml b/plugins/ebaystore/ofbiz-component.xml
index 31d6f22..39e48c2 100644
--- a/plugins/ebaystore/ofbiz-component.xml
+++ b/plugins/ebaystore/ofbiz-component.xml
@@ -1,48 +1,48 @@
-<?xml version="1.0" encoding="UTF-8"?>

-<!--

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

--->

-

-<ofbiz-component name="ebaystore" enabled="true"

-        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

-        xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/ofbiz-component.xsd">

-    <resource-loader name="main" type="component"/>

-    <classpath type="dir" location="config"/>

-

-    <entity-resource type="model" reader-name="main" loader="main" location="entitydef/entitymodel.xml"/>

-

-    <entity-resource type="data" reader-name="seed" loader="main" location="data/EbayStoreSecurityPermissionSeedData.xml"/>

-    <entity-resource type="data" reader-name="demo" loader="main" location="data/EbayStoreSecurityGroupDemoData.xml"/>

-    <entity-resource type="data" reader-name="seed" loader="main" location="data/EbayStoreTypeData.xml"/>

-    <entity-resource type="data" reader-name="seed" loader="main" location="data/EbayStoreHelpData.xml"/>

-    <entity-resource type="data" reader-name="seed" loader="main" location="data/EbayStorePortletData.xml"/>

-    <entity-resource type="data" reader-name="demo" loader="main" location="data/DemoEbayStoreData.xml"/>

-

-    <service-resource type="eca" loader="main" location="servicedef/secas.xml"/>

-    <service-resource type="model" loader="main" location="servicedef/services.xml"/>

-    <service-resource type="model" loader="main" location="servicedef/services_store.xml"/>

-

-    <webapp name="ebaystore"

-        title="eBay Store"

-        menu-name="secondary"

-        server="default-server"

-        location="webapp/ebaystore"

-        base-permission="EBAYSTORE"

-        mount-point="/ebaystore"

-        app-bar-display="true"/>

-</ofbiz-component>

+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+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.
+-->
+
+<ofbiz-component name="ebaystore" enabled="false"
+        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+        xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/ofbiz-component.xsd">
+    <resource-loader name="main" type="component"/>
+    <classpath type="dir" location="config"/>
+
+    <entity-resource type="model" reader-name="main" loader="main" location="entitydef/entitymodel.xml"/>
+
+    <entity-resource type="data" reader-name="seed" loader="main" location="data/EbayStoreSecurityPermissionSeedData.xml"/>
+    <entity-resource type="data" reader-name="demo" loader="main" location="data/EbayStoreSecurityGroupDemoData.xml"/>
+    <entity-resource type="data" reader-name="seed" loader="main" location="data/EbayStoreTypeData.xml"/>
+    <entity-resource type="data" reader-name="seed" loader="main" location="data/EbayStoreHelpData.xml"/>
+    <entity-resource type="data" reader-name="seed" loader="main" location="data/EbayStorePortletData.xml"/>
+    <entity-resource type="data" reader-name="demo" loader="main" location="data/DemoEbayStoreData.xml"/>
+
+    <service-resource type="eca" loader="main" location="servicedef/secas.xml"/>
+    <service-resource type="model" loader="main" location="servicedef/services.xml"/>
+    <service-resource type="model" loader="main" location="servicedef/services_store.xml"/>
+
+    <webapp name="ebaystore"
+        title="eBay Store"
+        menu-name="secondary"
+        server="default-server"
+        location="webapp/ebaystore"
+        base-permission="EBAYSTORE"
+        mount-point="/ebaystore"
+        app-bar-display="true"/>
+</ofbiz-component>