From 04f2a2ca3b20ab1ab1f485b428dbe79b0220cae3 Mon Sep 17 00:00:00 2001 From: Mathieu Lirzin Date: Fri, 1 Mar 2019 13:56:14 +0000 Subject: [PATCH] =?UTF-8?q?Improved:=20Replace=20=E2=80=98iterateOverActiv?= =?UTF-8?q?eComponents=E2=80=99=20with=20=E2=80=98activeComponents?= =?UTF-8?q?=E2=80=99=20in=20build=20script=20(OFBIZ-10695)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1854587 13f79535-47bb-0310-9956-ffa450edef68 --- build.gradle | 18 ++++++-------- common.gradle | 62 ++++++++++++++++++++++++------------------------- settings.gradle | 2 +- 3 files changed, 39 insertions(+), 43 deletions(-) diff --git a/build.gradle b/build.gradle index cb2864c910a..e942f867a6b 100644 --- a/build.gradle +++ b/build.gradle @@ -292,7 +292,7 @@ eclipse.classpath.file.whenMerged { classpath -> */ 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: docsGroup, type: AsciidoctorTask) { 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(group: docsGroup, 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, description: 'executes plugin install tas } 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: ofbizPlugin, 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 diff --git a/common.gradle b/common.gradle index e77c746b898..60f6a66d56a 100644 --- a/common.gradle +++ b/common.gradle @@ -16,43 +16,43 @@ * specific language governing permissions and limitations * under the License. */ -mkdir "${rootDir}/plugins" +import java.util.stream.Stream +import java.util.stream.Collectors -def iterateOverActiveComponents(applyFunction) { +mkdir "${rootDir}/plugins" - // Start is not a real component, therefore loading it manually - applyFunction file("${rootDir}/framework/start") +// The ‘file’ argument can be either a string or a file. +Stream xmlChildren(file) { + new XmlParser().parse(file).children().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" +Stream subdirs(File dir) { + def res = [] + dir.eachDir res.&add + res.stream() +} - 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 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() } diff --git a/settings.gradle b/settings.gradle index 25b7a5d53e5..0c0299410d9 100644 --- a/settings.gradle +++ b/settings.gradle @@ -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, ':')