Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Improved: Replace ‘iterateOverActiveComponents’ with ‘activeComponent…
…s’ in build script (OFBIZ-10695)

git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1854587 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
mthl committed Mar 1, 2019
1 parent e0d1308 commit 04f2a2c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 43 deletions.
18 changes: 7 additions & 11 deletions build.gradle
Expand Up @@ -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

Expand Down Expand Up @@ -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}"
Expand All @@ -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")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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')) {
Expand Down Expand Up @@ -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')) {
Expand Down Expand Up @@ -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
Expand Down
62 changes: 31 additions & 31 deletions common.gradle
Expand Up @@ -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<Node> 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<File> 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<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()
}
2 changes: 1 addition & 1 deletion settings.gradle
Expand Up @@ -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, ':')
Expand Down

0 comments on commit 04f2a2c

Please sign in to comment.