Skip to content
This repository has been archived by the owner on Mar 30, 2022. It is now read-only.

Commit

Permalink
Merge pull request #2 from blackducksoftware/using_hub_detect_model
Browse files Browse the repository at this point in the history
Using hub detect model
  • Loading branch information
James Richard committed Jul 31, 2017
2 parents e7391a2 + 96388a7 commit 4a47e54
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
6 changes: 5 additions & 1 deletion build.gradle
Expand Up @@ -7,12 +7,13 @@ tasks.withType(JavaCompile) { options.encoding = 'UTF-8' }
tasks.withType(GroovyCompile) { options.encoding = 'UTF-8' }

group = 'com.blackducksoftware.integration'
version = '0.1.1-SNAPSHOT'
version = '0.2.0-SNAPSHOT'

sourceCompatibility = 1.7
targetCompatibility = 1.7

repositories {
mavenLocal()
mavenCentral()
}

Expand Down Expand Up @@ -94,6 +95,9 @@ signing {
}

dependencies {
compile ('com.blackducksoftware.integration:hub-detect-model:0.0.1') {
exclude group: 'org.codehaus.groovy', module: 'groovy-all'
}
compile 'com.blackducksoftware.integration:integration-bdio:4.1.1'
compile 'com.google.code.gson:gson:2.7'
compile gradleApi()
Expand Down
Expand Up @@ -11,6 +11,8 @@ import org.slf4j.LoggerFactory

import com.blackducksoftware.integration.hub.bdio.simple.model.DependencyNode
import com.blackducksoftware.integration.hub.bdio.simple.model.externalid.MavenExternalId
import com.blackducksoftware.integration.hub.detect.model.BomToolType
import com.blackducksoftware.integration.hub.detect.model.DetectCodeLocation
import com.blackducksoftware.integration.util.ExcludedIncludedFilter
import com.google.gson.Gson
import com.google.gson.GsonBuilder
Expand Down Expand Up @@ -84,6 +86,52 @@ class DependencyGatherer {
}
}

void createAllCodeLocationFiles(final Project rootProject, String excludedProjectNames, String includedProjectNames, String excludedConfigurationNames, String includedConfigurationNames, File outputDirectory) {
ExcludedIncludedFilter projectFilter = new ExcludedIncludedFilter(excludedProjectNames, includedProjectNames)
ExcludedIncludedFilter configurationFilter = new ExcludedIncludedFilter(excludedConfigurationNames, includedConfigurationNames)
alreadyAddedIds = new HashSet<>()

String projectGroup = ''
String projectName = ''
String projectVersionName = ''
rootProject.allprojects.each { project ->
if (projectFilter.shouldInclude(project.name)) {
def group = project.group.toString()
def name = project.name.toString()
def version = project.version.toString()
if (!projectGroup) {
projectGroup = group
}
if (!projectName) {
projectName = name
}
if (!projectVersionName) {
projectVersionName = version
}
DependencyNode projectNode = new DependencyNode(name, version, new MavenExternalId(group, name, version))
project.configurations.each { configuration ->
ResolvedConfiguration resolvedConfiguration = resolveConfiguration(configuration, configurationFilter)
if (resolvedConfiguration != null) {
resolvedConfiguration.firstLevelModuleDependencies.each { dependency ->
addDependencyNodeToParent(projectNode, dependency)
}
}
}
File outputFile = new File(outputDirectory, "${group}_${name}_detectCodeLocation.json")
if (outputFile.exists()) {
outputFile.delete()
}
DetectCodeLocation codeLocation = new DetectCodeLocation(BomToolType.GRADLE, project.getProjectDir().getAbsolutePath(), projectName, projectVersionName, null,
new MavenExternalId(projectGroup, projectName, projectVersionName),projectNode.children)

Gson gson = new GsonBuilder().setPrettyPrinting().create()
JsonWriter jsonWriter = gson.newJsonWriter(new BufferedWriter(new FileWriter(outputFile)))
gson.toJson(codeLocation, DetectCodeLocation.class, jsonWriter)
jsonWriter.close()
}
}
}

private ResolvedConfiguration resolveConfiguration(Configuration configuration, ExcludedIncludedFilter configurationFilter) {
if (!configurationFilter.shouldInclude(configuration.name)) {
return null
Expand Down

0 comments on commit 4a47e54

Please sign in to comment.