Skip to content

Commit

Permalink
Merge pull request #161 from snyk/fix/scanning-lock-due-of-unresolved…
Browse files Browse the repository at this point in the history
…-dependencies

fix: scanning lock due of unresolved deps
  • Loading branch information
anthogez authored Feb 1, 2021
2 parents 20b5fdc + 23169a9 commit 1e289f3
Show file tree
Hide file tree
Showing 5 changed files with 1,022 additions and 26 deletions.
46 changes: 30 additions & 16 deletions lib/init.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import java.util.regex.Matcher
import org.gradle.util.GradleVersion

// Snyk dependency resolution script for Gradle.
// Tested on Gradle versions from 2.14 to 5.4.1
// Tested on Gradle versions from v2.14 to v6.8.1

// This script does the following: for all the projects in the build file,
// generate a merged configuration of all the available configurations,
Expand Down Expand Up @@ -129,6 +129,19 @@ def getSnykGraph(Iterable deps) {
return graph.nodes
}

def configsSuccessfullyResolved(configurations) {
def resolvedConfigurations = [];
configurations.each({ configuration ->
try {
configuration.resolve();
resolvedConfigurations.add(configuration);
} catch(Exception ex) {
println('NOT_RESOLVED ' + ex.toString())
}
})
return resolvedConfigurations;
}

// We are attaching this task to every project, as this is the only reliable way to run it
// when we start with a subproject build.gradle. As a consequence, we need to make sure we
// only ever run it once, for the "starting" project.
Expand Down Expand Up @@ -218,7 +231,8 @@ allprojects { everyProj ->
rootProject.allprojects.findAll(shouldScanProject).each { proj ->
println('SNYKECHO processing project: ' + proj.name)

def snykConf = null
def projectConfigs = null
def filteredProjectConfigs = null

// Gradle v3.0+ contains concepts as attributes, config canBeResolved, that does not exist in legacy versions
final GradleVersion gradleVersionInUse = GradleVersion.current();
Expand All @@ -230,40 +244,40 @@ allprojects { everyProj ->
// we can compute a dependency graph and that contains all the necessary information for resolution to happen.
if (confAttrSpec != null) {
// Drop all the configrations that don't match the attribute filter
snykConf = proj.configurations
.findAll({ it.canBeResolved == true && it.canBeConsumed == false && it.name =~ confNameFilter && matchesAttributeFilter(it) })
filteredProjectConfigs = proj.configurations.findAll({ it.canBeResolved == true && it.canBeConsumed == false && it.name =~ confNameFilter && matchesAttributeFilter(it) })

if(snykConf.size() == 0) {
snykConf = proj.configurations
if(filteredProjectConfigs.size() == 0) {
filteredProjectConfigs = proj.configurations
.findAll({ it.canBeResolved == true && it.canBeConsumed == true && it.name =~ confNameFilter && matchesAttributeFilter(it) })
}

projectConfigs = configsSuccessfullyResolved(filteredProjectConfigs)
} else {
snykConf = proj.configurations
.findAll({ it.canBeResolved == true && it.canBeConsumed == false && it.name =~ confNameFilter })

// if we cannot find dependencies that can be only resolved but not consumable
// we try to find configs that are simultaneously resolvable and consumable
// to prevent dependency resolution conflicts (e.g. Cannot choose between the following variants)
// we avoid the coexistence of (canBeResolved: true, canBeConsumed: false) and (canBeResolved: true, canBeConsumed: true) configs
if(snykConf.size() == 0) {
snykConf = proj.configurations
filteredProjectConfigs = proj.configurations.findAll({ it.canBeResolved == true && it.canBeConsumed == false && it.name =~ confNameFilter })
if(filteredProjectConfigs.size() == 0) {
filteredProjectConfigs = proj.configurations
.findAll({ it.canBeResolved == true && it.canBeConsumed == true && it.name =~ confNameFilter })
}
projectConfigs = configsSuccessfullyResolved(filteredProjectConfigs)
}
} else {
snykConf = proj.configurations.findAll({ it.name =~ confNameFilter })
def configsFilteredByConfName = proj.configurations.findAll({ it.name =~ confNameFilter })
projectConfigs = configsSuccessfullyResolved(configsFilteredByConfName)
}

if (snykConf.size() == 0 && proj.configurations.size() > 0) {
if (projectConfigs.size() == 0 && proj.configurations.size() > 0) {
throw new RuntimeException('Matching configurations not found: ' + confNameFilter +
', available configurations for project ' + proj + ': '
+ proj.configurations.collect { it.name })
}

if (snykConf != null) {
println('SNYKECHO resolving configuration ' + snykConf.name)
def gradleFirstLevelDeps = snykConf.resolvedConfiguration.firstLevelModuleDependencies
if (projectConfigs != null) {
println('SNYKECHO resolving configuration ' + projectConfigs.name)
def gradleFirstLevelDeps = projectConfigs.resolvedConfiguration.firstLevelModuleDependencies.findAll({ it.size() > 0 })
println('SNYKECHO converting gradle graph to snyk-graph format')
projectsDict[proj.name] = [
'targetFile': findProject(proj.path).buildFile.toString(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
plugins {
id 'io.gatling.gradle' version "3.5.0"
}

build.dependsOn gatlingClasses

dependencies {
gatling group: 'org.scalaj', name: 'scalaj-http_2.13', version: '2.4.2'
}

gatling {
simulations = {
exclude "**/paxos/BaseSimulation.scala"
exclude "**/paxos/Configuration.scala"
}
}
Loading

0 comments on commit 1e289f3

Please sign in to comment.