Skip to content

Commit

Permalink
#JENKINS-38938 - Adding support for global data directory (with per-j…
Browse files Browse the repository at this point in the history
…ob override).
  • Loading branch information
stevespringett committed Oct 12, 2016
1 parent 3efb37d commit 915576c
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 10 deletions.
Expand Up @@ -153,9 +153,10 @@ private boolean isSkip(AbstractBuild build, BuildListener listener) {
*
* @return A boolean indicating if any errors occurred during the validation process
*/
protected boolean configureDataDirectory(AbstractBuild build, BuildListener listener, Options options, String dataDir) {
protected boolean configureDataDirectory(AbstractBuild build, BuildListener listener, Options options,
String globalDataDir, String dataDir) {
FilePath dataPath;
if (StringUtils.isBlank(dataDir)) {
if (StringUtils.isBlank(globalDataDir) && StringUtils.isBlank(dataDir)) {
// datadir was not specified, so use the default 'dependency-check-data' directory
// located in the builds workspace.
dataPath = new FilePath(build.getWorkspace(), "dependency-check-data");
Expand All @@ -167,8 +168,13 @@ protected boolean configureDataDirectory(AbstractBuild build, BuildListener list
return false;
}
} else {
// datadir was specified.
dataPath = new FilePath(build.getWorkspace(), substituteVariable(build, listener, dataDir));
if (!StringUtils.isBlank(dataDir)) {
// job-specific datadir was specified. Override the global setting
dataPath = new FilePath(build.getWorkspace(), substituteVariable(build, listener, dataDir));
} else {
// use the global setting
dataPath = new FilePath(build.getWorkspace(), substituteVariable(build, listener, globalDataDir));
}
}
options.setDataDirectory(dataPath.getRemote());
return true;
Expand Down
Expand Up @@ -220,7 +220,7 @@ private Options generateOptions(AbstractBuild build, BuildListener listener) {
final Options options = optionsBuilder(build, listener, outdir, isVerboseLoggingEnabled, this.getDescriptor().getTempPath(), this.getDescriptor().isQuickQueryTimestampEnabled);

// Configure universal settings useful for all Builder steps
configureDataDirectory(build, listener, options, datadir);
configureDataDirectory(build, listener, options, this.getDescriptor().getGlobalDataDirectory(), datadir);
configureDataMirroring(options, this.getDescriptor().getDataMirroringType(),
this.getDescriptor().getCveUrl12Modified(), this.getDescriptor().getCveUrl20Modified(),
this.getDescriptor().getCveUrl12Base(), this.getDescriptor().getCveUrl20Base());
Expand Down Expand Up @@ -550,6 +550,11 @@ public static final class DescriptorImpl extends BuildStepDescriptor<Builder> {
*/
private String tempPath;

/**
* Specifies the global data directory
*/
private String globalDataDirectory;

/**
* Specifies if QuickQuery is enabled or not. If enabled, HTTP HEAD will be used.
*/
Expand Down Expand Up @@ -685,6 +690,7 @@ public boolean configure(StaplerRequest req, JSONObject formData) throws FormExc
dbuser = formData.getString("dbuser");
dbpassword = formData.getString("dbpassword");
tempPath = formData.getString("tempPath");
globalDataDirectory = formData.getString("globalDataDirectory");
isQuickQueryTimestampEnabled = formData.getBoolean("isQuickQueryTimestampEnabled");
save();
return super.configure(req, formData);
Expand Down Expand Up @@ -865,6 +871,13 @@ public String getTempPath() {
return tempPath;
}

/**
* Returns the global configuration for the path to the data directory.
*/
public String getGlobalDataDirectory() {
return globalDataDirectory;
}

/**
* Retrieves the database connection string that DependencyCheck will use. This is a per-build config item.
* This method must match the value in <tt>config.jelly</tt>.
Expand Down
Expand Up @@ -95,7 +95,7 @@ private Options generateOptions(AbstractBuild build, BuildListener listener) {
final Options options = optionsBuilder(build, listener, null, isVerboseLoggingEnabled, this.getDescriptor().getTempPath(), this.getDescriptor().getIsQuickQueryTimestampEnabled());

// Configure universal settings useful for all Builder steps
configureDataDirectory(build, listener, options, datadir);
configureDataDirectory(build, listener, options, this.getDescriptor().getGlobalDataDirectory(), datadir);
configureDataMirroring(options, this.getDescriptor().getDataMirroringType(),
this.getDescriptor().getCveUrl12Modified(), this.getDescriptor().getCveUrl20Modified(),
this.getDescriptor().getCveUrl12Base(), this.getDescriptor().getCveUrl20Base());
Expand Down Expand Up @@ -214,6 +214,13 @@ public String getTempPath() {
return globalDcDescriptor.getTempPath();
}

/**
* Returns the global configuration for the path to the data directory.
*/
public String getGlobalDataDirectory() {
return globalDcDescriptor.getGlobalDataDirectory();
}

/**
* Returns if QuickQuery is enabled or not. If enabled, HTTP HEAD will be used.
*/
Expand Down
Expand Up @@ -23,6 +23,11 @@ limitations under the License.
<f:textbox id="temp.path"/>
</f:entry>

<f:entry title="${%global.data.directory}" field="globalDataDirectory"
help="/plugin/dependency-check-jenkins-plugin/help-datadir.html">
<f:textbox id="globalDataDirectory"/>
</f:entry>

<f:advanced>

<f:entry title="${%db.connection.string}" field="dbconnstr" help="/plugin/dependency-check-jenkins-plugin/help-database-connstring.html">
Expand Down
Expand Up @@ -32,6 +32,7 @@ nexus.url=Nexus service URL
nexus.proxy.bypass=Bypass proxy for Nexus analyzer
mono.path=Path to Mono (MDK/MRE) binary
temp.path=Temporary directory
global.data.directory=Global Data Directory
jar.enabled=Enable JAR analyzer
nodejs.enabled=Enable Node.js analyzer
composerlock.enabled=Enable PHP Composer.lock analyzer
Expand Down
23 changes: 19 additions & 4 deletions src/main/webapp/help-datadir.html
@@ -1,6 +1,21 @@
<div>
If specified, Dependency-Check will create and utilize this
directory for it's data directory. If the data directory
is not specified, the default 'dependency-check-data'
directory will be created in the projects workspace.
<p>
If specified, Dependency-Check will create and utilize this directory for
it's data directory.
</p>
<p>
The data directory typically contains the embedded H2 database with all NVD
vulnerabilities along with Lucene indexes for fast and efficient searching.
</p>
<p>
Data directory resolution occurs as follows:
<ul>
<li>Each job automatically inherits the globally defined data directory
(if specified)</li>
<li>The data directory can independently be controlled on a per-job basis,
overriding the global value</li>
<li>If neither a global or per-job data directory is specified,
'dependency-check-data' will be created in the projects workspace</li>
</ul>
</p>
</div>

0 comments on commit 915576c

Please sign in to comment.