Table of Contents
| The table of contents of this series | The next article in this series>
import java.nio.file.Paths;
import java.nio.file.LinkOption;
Paths.get (".").toRealPath (LinkOption.NOFOLLOW_LINKS)
gradle -p $(pwd)
gradle -Dc_projectDirectoryPath=$(pwd)
gradle -p /a/b/c -Dc_projectDirectoryPath=/a/b/c
Gradle.sh -p /a/b/c
Gradle.sh
Gradle.sh -p c
#!/bin/bash
declare -a l_commandLineArguments=()
declare l_projectDirectoryPathSettingFlag=false
declare l_projectDirectoryPath="$(pwd)"
declare -i l_commandLineArgumentIndex=4
for l_commandLineArgument in "$@"
do
if [ "${l_commandLineArgument}" == -p ]
then
l_projectDirectoryPathSettingFlag=true
else
if [ "${l_projectDirectoryPathSettingFlag}" == true ]
then
l_projectDirectoryPath="${l_commandLineArgument}"
else
l_commandLineArguments["${l_commandLineArgumentIndex}"]="${l_commandLineArgument}"
l_commandLineArgumentIndex=(${l_commandLineArgumentIndex}+1)
fi
l_projectDirectoryPathSettingFlag=false
fi
done
l_commandLineArguments[0]="-Duser.dir=$(pwd)"
l_commandLineArguments[1]=-p
l_commandLineArguments[2]="${l_projectDirectoryPath}"
l_commandLineArguments[3]="-Dc_projectDirectoryPath=${l_projectDirectoryPath}"
set -x
gradle "${l_commandLineArguments[@]}"
import java.io.File
import java.nio.file.LinkOption;
import java.nio.file.Paths;
ext ({
// Property Names Start
c_operatingSystemNamePropertyName = "os.name"
c_currentDirectoryPathPropertyName = "user.dir"
c_projectDirectoryPathPropertyName = "c_projectDirectoryPath"
// Property Names End
// Operating System Names Start
c_operatingSystemNameLinux = "Linux"
// Operating System Names End
// Directories Separators Start
if (System.properties [c_operatingSystemNamePropertyName].startsWith (c_operatingSystemNameLinux)) {
c_operatingSystemDirectoriesSeparator = "/"
}
else {
c_operatingSystemDirectoriesSeparator = "\\"
}
// Directories Separators End
// Closures Part 1 Start
getDirectoryOrFileNormalizedPathFromPath = {String a_directoryOrFilePath ->
Paths.get (a_directoryOrFilePath).normalize ().toString ()
}
getDirectoryOrFileNormalizedAbsolutePathFromPathWithBaseSpecified = {String a_directoryOrFilePath, String a_baseDirectoryOrFilePath ->
if (a_directoryOrFilePath == null) {
null
}
else {
def l_directoryOrFileAbsolutePath = null
if (!(new File (a_directoryOrFilePath)).isAbsolute ()) {
l_directoryOrFileAbsolutePath = "${a_baseDirectoryOrFilePath}${c_operatingSystemDirectoriesSeparator}${a_directoryOrFilePath}"
}
else {
l_directoryOrFileAbsolutePath = a_directoryOrFilePath
}
getDirectoryOrFileNormalizedPathFromPath (l_directoryOrFileAbsolutePath)
}
}
// Closures Part 1 End
// Directory Paths Start
c_currentDirectoryPath = getDirectoryOrFileNormalizedPathFromPath (System.getProperty (c_currentDirectoryPathPropertyName))
c_projectDirectoryPath = getDirectoryOrFileNormalizedAbsolutePathFromPathWithBaseSpecified (System.getProperty (c_projectDirectoryPathPropertyName), c_currentDirectoryPath)
if (c_projectDirectoryPath == null) {
c_projectDirectoryPath = projectDir.getPath ()
}
// Directory Paths End
// Closures Part 2 Start
getDirectoryOrFileNormalizedAbsolutePathFromPath = {String a_directoryOrFilePath ->
getDirectoryOrFileNormalizedAbsolutePathFromPathWithBaseSpecified (a_directoryOrFilePath, c_projectDirectoryPath)
}
// Closures Part 2 End
})
ext ({
// Property Names Start
c_isSubProjectPropertyName = "c_isSubProject"
// Property Names End
// Path Names Start
c_parentDirectoryPathName = ".."
// Path Names End
// File Names Start
c_gradleDefaultBuildScriptName = "build.gradle"
// File Names End
// Project Properties Start
c_isSubProject = System.getProperty (c_isSubProjectPropertyName)
if (c_isSubProject == null) {
c_isSubProject = "false"
}
// Project Properties End
// Task Name Prefixes Start
c_referencedProjectTaskCallTaskNamePrefix = "i_callReferencedProject"
// Task Name Prefixes End
// Task Name Suffixes Start
c_referencedProjectTaskCallTaskNameSuffix = "Task"
// Task Name Suffixes End
// In Task Name Directories Separator Start
c_referencedProjectTaskCallTaskNameDirectoriesSeparator = "#"
// In Task Name Directories Separator End
// Task Names Start
c_testTaskName = "i_testTask"
// Task Names End
})
ext ({
c_targetName = "theBiasPlanet.gradleTestsMainProject"
c_referencedProjectDirectoryPaths = ["${c_parentDirectoryPathName}${c_operatingSystemDirectoriesSeparator}gradleTestsSubProject"]
})
defaultTasks (c_testTaskName)
task (c_testTaskName + "", type: DefaultTask, {
println (String.format ("### In the task creation: project = %s, task = %s", c_targetName, c_testTaskName))
doFirst ({
println (String.format ("### In doFirst: project = %s, task = %s", c_targetName, c_testTaskName))
})
doLast ({
println (String.format ("### In doLast: project = %s, task = %s", c_targetName, c_testTaskName))
})
})
if (!c_isSubProject.equals ("true")) {
def Task l_lastReferencedProjectTask = null
c_referencedProjectDirectoryPaths.each ({String a_referencedProjectDirectoryPath ->
def String l_referencedProjectDirectoryAbsolutePath = getDirectoryOrFileNormalizedAbsolutePathFromPath (a_referencedProjectDirectoryPath)
def Task l_referencedProjectTask = task (c_referencedProjectTaskCallTaskNamePrefix + a_referencedProjectDirectoryPath.replaceAll (c_operatingSystemDirectoriesSeparator, c_referencedProjectTaskCallTaskNameDirectoriesSeparator) + c_referencedProjectTaskCallTaskNameSuffix, type: GradleBuild, {
buildFile = getDirectoryOrFileNormalizedAbsolutePathFromPathWithBaseSpecified (c_gradleDefaultBuildScriptName, l_referencedProjectDirectoryAbsolutePath)
tasks = [c_testTaskName]
startParameter.setSystemPropertiesArgs ([(c_currentDirectoryPathPropertyName + ""): c_currentDirectoryPath, (c_projectDirectoryPathPropertyName + ""): l_referencedProjectDirectoryAbsolutePath, (c_isSubProjectPropertyName + ""): "true"])
})
if (l_lastReferencedProjectTask != null) {
l_referencedProjectTask.mustRunAfter (l_lastReferencedProjectTask)
}
tasks [c_testTaskName].dependsOn += l_referencedProjectTask
l_lastReferencedProjectTask = l_referencedProjectTask
})
if (l_lastReferencedProjectTask != null) {
tasks [c_testTaskName].mustRunAfter (l_lastReferencedProjectTask)
}
}