diff --git a/build.gradle b/build.gradle index cb2864c910..e942f867a6 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 e77c746b89..60f6a66d56 100644 --- a/common.gradle +++ b/common.gradle @@ -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) { - - // Start is not a real component, therefore loading it manually - applyFunction file("${rootDir}/framework/start") - - 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) - } - } - } +// The ‘file’ argument can be either a string or a file. +Stream xmlChildren(file) { + new XmlParser().parse(file).children().stream() } -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 - } - } +Stream subdirs(File dir) { + def res = [] + dir.eachDir res.&add + res.stream() } -ext{ - iterateOverActiveComponents = this.&iterateOverActiveComponents +boolean isComponentEnabled(File componentDir) { + File componentFile = file(componentDir.toString() + '/ofbiz-component.xml') + componentFile.exists() && new XmlParser().parse(componentFile) + .with { it.@enabled in [null, 'true'] } +} + +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 { + activeComponents = this.&activeComponents.memoize() } diff --git a/settings.gradle b/settings.gradle index 25b7a5d53e..0c0299410d 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, ':')