Author: mthl
Date: Fri Mar 1 13:56:14 2019
New Revision: 1854587
URL: http://svn.apache.org/viewvc?rev=1854587&view=rev
Log:
Improved: Replace ‘iterateOverActiveComponents’ with ‘activeComponents’ in
build script (OFBIZ-10695)
Modified:
ofbiz/ofbiz-framework/trunk/build.gradle
ofbiz/ofbiz-framework/trunk/common.gradle
ofbiz/ofbiz-framework/trunk/settings.gradle
Modified: ofbiz/ofbiz-framework/trunk/build.gradle
URL:
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/build.gradle?rev=1854587&r1=1854586&r2=1854587&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/build.gradle (original)
+++ ofbiz/ofbiz-framework/trunk/build.gradle Fri Mar 1 13:56:14 2019
@@ -292,7 +292,7 @@ eclipse.classpath.file.whenMerged { clas
*/
def fileSep = System.getProperty("file.separator")
- iterateOverActiveComponents { component ->
+ activeComponents().each { component ->
def componentName = component.toString() - rootDir.toString() - fileSep
def eclipseEntry = os.contains('windows') ?
componentName.replaceAll("\\\\", "/") : componentName
@@ -526,15 +526,11 @@ task deleteOfbizDocumentation {
}
task deletePluginDocumentation {
- def activeComponents = []
- iterateOverActiveComponents { component ->
- activeComponents.add(component.name)
- }
doFirst {
if (!project.hasProperty('pluginId')) {
throw new GradleException('Missing property \"pluginId\"')
}
- if(!activeComponents.contains(pluginId)) {
+ if(!activeComponents().contains(pluginId)) {
throw new GradleException("Could not find plugin with id
${pluginId}")
}
delete "${buildDir}/asciidoc/plugins/${pluginId}"
@@ -556,7 +552,7 @@ task generateOfbizDocumentation(group: d
task generatePluginDocumentation(group: docsGroup) {
dependsOn deletePluginDocumentation
description 'Generate plugin documentation. Expects pluginId flag'
- iterateOverActiveComponents { component ->
+ activeComponents().each { component ->
if (project.hasProperty('pluginId') && component.name == pluginId) {
def pluginAsciidoc = task "${component.name}Documentation" (type:
AsciidoctorTask) {
def asciidocFolder = new File("${component}/src/docs/asciidoc")
@@ -585,7 +581,7 @@ task generateAllPluginsDocumentation(gro
dependsOn deleteAllPluginsDocumentation
file("${pluginsDir}").eachDir { plugin ->
- iterateOverActiveComponents { component ->
+ activeComponents().each { component ->
if (component.name == plugin.name) {
if (subprojectExists(":plugins:${plugin.name}")) {
// Note: the "-" between "component.name" and
"Documentation" allows to differentiate from
@@ -751,7 +747,7 @@ task installPlugin(group: ofbizPlugin, d
}
if (project.hasProperty('pluginId')) {
- iterateOverActiveComponents { component ->
+ activeComponents().each { component ->
if (component.name == pluginId) {
if (subprojectExists(":plugins:${pluginId}")) {
if (taskExistsInproject(":plugins:${pluginId}",
'install')) {
@@ -911,7 +907,7 @@ task pullAllPluginsSource(group: ofbizPl
task installAllPlugins {
file("${pluginsDir}").eachDir { plugin ->
- iterateOverActiveComponents { component ->
+ activeComponents().each { component ->
if (component.name == plugin.name) {
if (subprojectExists(":plugins:${plugin.name}")) {
if (taskExistsInproject(":plugins:${plugin.name}",
'install')) {
@@ -1055,7 +1051,7 @@ def spawnProcess(command) {
def getDirectoryInActiveComponentsIfExists(String dirName) {
def dirInComponents = []
- iterateOverActiveComponents { component ->
+ activeComponents().each { component ->
def subDir = file(component.toString() + '/' + dirName)
if (subDir.exists()) {
dirInComponents.add subDir
Modified: ofbiz/ofbiz-framework/trunk/common.gradle
URL:
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/common.gradle?rev=1854587&r1=1854586&r2=1854587&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/common.gradle (original)
+++ ofbiz/ofbiz-framework/trunk/common.gradle Fri Mar 1 13:56:14 2019
@@ -16,43 +16,43 @@
* specific language governing permissions and limitations
* under the License.
*/
+import java.util.stream.Stream
+import java.util.stream.Collectors
+
mkdir "${rootDir}/plugins"
-def iterateOverActiveComponents(applyFunction) {
+// The âfileâ argument can be either a string or a file.
+Stream<Node> xmlChildren(file) {
+ new XmlParser().parse(file).children().stream()
+}
- // Start is not a real component, therefore loading it manually
- applyFunction file("${rootDir}/framework/start")
+Stream<File> subdirs(File dir) {
+ def res = []
+ dir.eachDir res.&add
+ res.stream()
+}
- 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"
-
- 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)
- }
- }
- }
+boolean isComponentEnabled(File componentDir) {
+ File componentFile = file(componentDir.toString() + '/ofbiz-component.xml')
+ componentFile.exists() && new XmlParser().parse(componentFile)
+ .with { it.@enabled in [null,
'true'] }
}
-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
- }
- }
+List<File> activeComponents() {
+ xmlChildren("${rootDir}/framework/base/config/component-load.xml")
+ .map { "${rootDir}/" + it.@'parent-directory' }
+ .flatMap({ dir ->
+ File loader = file(dir + '/component-load.xml')
+ if (loader.exists()) {
+ xmlChildren(loader).map { file dir + '/' +
it.@'component-location' }
+ } else {
+ subdirs file(dir)
+ }
+ })
+ .filter(this.&isComponentEnabled)
+ .collect(Collectors.toList()) + file("${rootDir}/framework/start")
}
-ext{
- iterateOverActiveComponents = this.&iterateOverActiveComponents
+ext {
+ activeComponents = this.&activeComponents.memoize()
}
Modified: ofbiz/ofbiz-framework/trunk/settings.gradle
URL:
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/settings.gradle?rev=1854587&r1=1854586&r2=1854587&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/settings.gradle (original)
+++ ofbiz/ofbiz-framework/trunk/settings.gradle Fri Mar 1 13:56:14 2019
@@ -23,7 +23,7 @@ rootProject.name = 'ofbiz'
def fileSep = System.getProperty("file.separator")
def isWindows = System.getProperty('os.name').toLowerCase().contains("windows")
-iterateOverActiveComponents { File component ->
+activeComponents().each { File component ->
def subProject = (component.toString() - rootDir)
if (isWindows)
include subProject.replaceAll('\\' + fileSep, ':')