refactor: Use renamed utility class and add comments.
@@ -4,7 +4,7 @@ import org.gradle.api.Task
import org.gradle.api.execution.TaskExecutionListener
import org.gradle.api.tasks.TaskState
-import com.blackducksoftware.integration.gradle.DependencyGathererUtil
+import com.blackducksoftware.integration.gradle.DependencyDataUtil
initscript {
repositories {
@@ -36,12 +36,14 @@ initscript {
}
gradle.allprojects {
+ // add a new task to each project to start the process of getting the dependencies
task gatherDependencies(type: DefaultTask) {
doLast {
println "Gathering dependencies for " + project.name
}
}
afterEvaluate { project ->
+ // after a project has been evaluated modify the dependencies task for that project to output to a specific file.
project.tasks.getByName('dependencies') {
ext {
excludedProjectNames = '${excludedProjectNames}'
@@ -51,24 +53,31 @@ gradle.allprojects {
outputDirectoryPath = System.getProperty('GRADLEEXTRACTIONDIR')
}
doFirst {
- DependencyGathererUtil dependencyUtil = new DependencyGathererUtil()
+ DependencyDataUtil dependencyUtil = new DependencyDataUtil()
dependencyUtil.generateRootProjectMetaData(project, outputDirectoryPath)
- setConfigurations(dependencyUtil.filterConfigurations(project, excludedConfigurationNames, includedConfigurationNames))
+
+ // this will be empty if the project should not be included.
Optional<File> projectOutputFile = dependencyUtil.getProjectOutputFile(project, outputDirectoryPath, excludedProjectNames, includedProjectNames)
if(projectOutputFile.isPresent()) {
File projectFile = dependencyUtil.createProjectOutputFile(projectOutputFile.get())
+
+ // modify the configurations for the dependency task and the output file
+ setConfigurations(dependencyUtil.filterConfigurations(project, excludedConfigurationNames, includedConfigurationNames))
setOutputFile(projectFile)
}
}
doLast {
- DependencyGathererUtil dependencyUtil = new DependencyGathererUtil()
+ DependencyDataUtil dependencyUtil = new DependencyDataUtil()
+
+ // this will be empty if this project should not be included.
Optional<File> projectFile = dependencyUtil.getProjectOutputFile(project, outputDirectoryPath, excludedProjectNames, includedProjectNames)
if(projectFile.isPresent()) {
- dependencyUtil.createProjectMetadata(project, projectFile.get())
+ dependencyUtil.appendProjectMetadata(project, projectFile.get())
}
}
}
+ // this forces the dependencies task to be run which will write the content to the modified output file
project.gatherDependencies.finalizedBy(project.tasks.getByName('dependencies'))
project.gatherDependencies
}
