Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ class AnalyzerExtension {
private final Property<String> zipExtensions
private final Property<Boolean> jarEnabled
private final Property<Boolean> centralEnabled
private final Property<Boolean> nexusEnabled
private final Property<String> nexusUrl
private final Property<Boolean> nexusUsesProxy
private final Property<Boolean> nuspecEnabled
private final Property<Boolean> assemblyEnabled
private final Property<Boolean> msbuildEnabled
Expand Down Expand Up @@ -77,9 +74,6 @@ class AnalyzerExtension {
this.zipExtensions = objects.property(String)
this.jarEnabled = objects.property(Boolean)
this.centralEnabled = objects.property(Boolean)
this.nexusEnabled = objects.property(Boolean)
this.nexusUrl = objects.property(String)
this.nexusUsesProxy = objects.property(Boolean)
this.nuspecEnabled = objects.property(Boolean)
this.assemblyEnabled = objects.property(Boolean)
this.msbuildEnabled = objects.property(Boolean)
Expand Down Expand Up @@ -112,6 +106,7 @@ class AnalyzerExtension {
nodePackage = objects.newInstance(NodePackageExtension, objects)
artifactory = objects.newInstance(ArtifactoryExtension, objects)
ossIndex = objects.newInstance(OssIndexExtension, objects)
nexus = objects.newInstance(NexusExtension)
}

/**
Expand Down Expand Up @@ -181,41 +176,53 @@ class AnalyzerExtension {

/**
* Sets whether Nexus Analyzer will be used. This analyzer is superceded by the Central Analyzer; however, you can configure this to run against a Nexus Pro installation.
* @deprecated use nexus { enabled = true }
*/
@Input
@Optional
@Deprecated
Property<Boolean> getNexusEnabled() {
return nexusEnabled
return nexus.enabled
}

/* @deprecated use nexus { enabled = true } */
@Deprecated
void setNexusEnabled(Boolean value) {
nexusEnabled.set(value)
nexus.enabled.set(value)
}

/**
* Defines the Nexus Server's web service end point (example http://domain.enterprise/service/local/). If not set the Nexus Analyzer will be disabled.
* @deprecated use nexus { url = "nexus url" }
*/
@Input
@Optional
@Deprecated
Property<String> getNexusUrl() {
return nexusUrl
return nexus.url
}

/* @deprecated use nexus { url = "nexus url" } */
@Deprecated
void setNexusUrl(String value) {
nexusUrl.set(value)
nexus.url.set(value)
}

/**
* whether the defined proxy should be used when connecting to Nexus.
* @deprecated use nexus { usesProxy = true }
*/
@Input
@Optional
@Deprecated
Property<Boolean> getNexusUsesProxy() {
return nexusUsesProxy
return nexus.usesProxy
}

/* @deprecated use nexus { usesProxy = true } */
@Deprecated
void setNexusUsesProxy(Boolean value) {
nexusUsesProxy.set(value)
nexus.usesProxy.set(value)
}

/**
Expand Down Expand Up @@ -593,6 +600,11 @@ class AnalyzerExtension {
*/
OssIndexExtension ossIndex

/**
* Nexus configuration extension.
*/
NexusExtension nexus

/**
* Allows programmatic configuration of the KEV extension
* @param configClosure the closure to configure the KEV extension
Expand Down Expand Up @@ -718,4 +730,14 @@ class AnalyzerExtension {
config.execute(nodePackage)
return nodePackage
}

/**
* Allows programmatic configuration of the nexus extension
* @param config the action to configure nexus extension
* @return nexus extension
*/
def nexus(Action<NexusExtension> config) {
config.execute(nexus)
return nexus
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class DependencyCheckExtension {
nvd = objects.newInstance(NvdExtension, objects)
hostedSuppressions = objects.newInstance(HostedSuppressionsExtension, objects)
data = objects.newInstance(DataExtension, objects, project)
analyzers = new AnalyzerExtension(project, objects)
analyzers = objects.newInstance(AnalyzerExtension, project, objects)
additionalCpes = project.objects.domainObjectContainer(AdditionalCpe.class)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package org.owasp.dependencycheck.gradle.extension

import org.gradle.api.provider.Property
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.Optional

/**
* Nexus analyzer configuration.
*/
interface NexusExtension {

/**
* Sets whether the Nexus Analyzer should be used.
*/
@Input
@Optional
Property<Boolean> getEnabled()

/**
* Nexus server URL.
*/
@Input
@Optional
Property<String> getUrl()

/**
* Whether Nexus should be accessed through a proxy.
*/
@Input
@Optional
Property<Boolean> getUsesProxy()

/**
* Nexus basic auth username.
*/
@Input
@Optional
Property<String> getUsername()

/**
* Nexus basic auth password.
*/
@Input
@Optional
Property<String> getPassword()

}
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,11 @@ abstract class ConfiguredTask extends DefaultTask {

settings.setBooleanIfNotNull(ANALYZER_CENTRAL_ENABLED, config.analyzers.centralEnabled.getOrNull())

settings.setBooleanIfNotNull(ANALYZER_NEXUS_ENABLED, config.analyzers.nexusEnabled.getOrNull())
settings.setStringIfNotEmpty(ANALYZER_NEXUS_URL, config.analyzers.nexusUrl.getOrNull())
settings.setBooleanIfNotNull(ANALYZER_NEXUS_USES_PROXY, config.analyzers.nexusUsesProxy.getOrNull())
settings.setBooleanIfNotNull(ANALYZER_NEXUS_ENABLED, config.analyzers.nexus.enabled.getOrNull())
settings.setStringIfNotEmpty(ANALYZER_NEXUS_URL, config.analyzers.nexus.url.getOrNull())
settings.setBooleanIfNotNull(ANALYZER_NEXUS_USES_PROXY, config.analyzers.nexus.usesProxy.getOrNull())
settings.setStringIfNotNull(ANALYZER_NEXUS_USER, config.analyzers.nexus.username.getOrNull())
settings.setStringIfNotNull(ANALYZER_NEXUS_PASSWORD, config.analyzers.nexus.password.getOrNull())

settings.setBooleanIfNotNull(ANALYZER_EXPERIMENTAL_ENABLED, config.analyzers.experimentalEnabled.getOrNull())
settings.setBooleanIfNotNull(ANALYZER_ARCHIVE_ENABLED, config.analyzers.archiveEnabled.getOrNull())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import org.gradle.testfixtures.ProjectBuilder
import org.owasp.dependencycheck.gradle.extension.DependencyCheckExtension
import spock.lang.Specification

import static org.owasp.dependencycheck.utils.Settings.KEYS.*

class DependencyCheckGradlePluginSpec extends Specification {
static final String PLUGIN_ID = 'org.owasp.dependencycheck'
Project project
Expand Down Expand Up @@ -198,6 +200,56 @@ class DependencyCheckGradlePluginSpec extends Specification {

}

def 'legacy nexus properties mapped to NexusExtension'() {
given:
project.dependencyCheck {
analyzers.nexusEnabled = enabled
analyzers.nexusUrl = url
analyzers.nexusUsesProxy = proxy
}

expect:
project.dependencyCheck {
assert analyzers.nexus.enabled.get() == enabled
assert analyzers.nexus.url.get() == url
assert analyzers.nexus.usesProxy.get() == proxy
}

where:
enabled | url | proxy
true | 'http://someurl' | true
false | 'https://testurl' | false
}

def 'NexusExtension properties configure task settings'() {
given:
def task = project.tasks.findByName(taskName)
with(project.dependencyCheck.analyzers.nexus) {
enabled.set(true)
usesProxy.set(true)
url.set('http://nexus')
username.set('user')
password.set('pass')
}

when:
task.initializeSettings()

then:
with(task.settings) {
getBoolean(ANALYZER_NEXUS_ENABLED) == true
getBoolean(ANALYZER_NEXUS_USES_PROXY) == true
getString(ANALYZER_NEXUS_URL) == 'http://nexus'
getString(ANALYZER_NEXUS_USER) == 'user'
getString(ANALYZER_NEXUS_PASSWORD) == 'pass'
}

where:
taskName | _
DependencyCheckPlugin.ANALYZE_TASK | _
DependencyCheckPlugin.AGGREGATE_TASK | _
}

def 'scanConfigurations and skipConfigurations are mutually exclusive'() {
when:
project.dependencyCheck {
Expand Down
Loading