-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from Liftric/refactor/riskScore_task
refactor: Decoupling Project Analysis from Risk Score Check
- Loading branch information
Showing
4 changed files
with
86 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/main/kotlin/com/liftric/dtcp/tasks/AnalyzeProjectTask.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.liftric.dtcp.tasks | ||
|
||
import com.liftric.dtcp.service.DependencyTrack | ||
import org.gradle.api.DefaultTask | ||
import org.gradle.api.GradleException | ||
import org.gradle.api.provider.Property | ||
import org.gradle.api.tasks.TaskAction | ||
import org.gradle.api.tasks.Input | ||
import org.gradle.api.tasks.Optional | ||
|
||
abstract class AnalyzeProjectTask : DefaultTask() { | ||
@get:Input | ||
abstract val apiKey: Property<String> | ||
|
||
@get:Input | ||
abstract val url: Property<String> | ||
|
||
@get:Input | ||
@get:Optional | ||
abstract val projectUUID: Property<String> | ||
|
||
@get:Input | ||
@get:Optional | ||
abstract val projectName: Property<String> | ||
|
||
@get:Input | ||
@get:Optional | ||
abstract val projectVersion: Property<String> | ||
|
||
@TaskAction | ||
fun analyzeProjectTask() { | ||
val apiKeyValue = apiKey.get() | ||
val urlValue = url.get() | ||
|
||
val projectUUIDValue = projectUUID.orNull | ||
val projectNameValue = projectName.orNull | ||
val projectVersionValue = projectVersion.orNull | ||
|
||
val dt = DependencyTrack(apiKeyValue, urlValue) | ||
|
||
val uuid = when { | ||
projectUUIDValue != null -> projectUUIDValue | ||
projectNameValue != null && projectVersionValue != null -> dt.getProject( | ||
projectNameValue, | ||
projectVersionValue | ||
).uuid | ||
|
||
else -> throw GradleException("Either projectUUID or projectName and projectVersion must be set") | ||
} | ||
|
||
dt.analyzeProjectFindings(uuid) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters