Skip to content

Commit 4eed6c5

Browse files
committed
DependencyTrack#4620 add "lastVulnerabilityAnalysis" to project
Signed-off-by: Steffen Ohrendorf <[email protected]>
1 parent b42212f commit 4eed6c5

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

src/main/java/org/dependencytrack/model/Project.java

+16
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,14 @@ public enum FetchGroup {
291291
@Column(name = "LAST_RISKSCORE", allowsNull = "true") // New column, must allow nulls on existing databases))
292292
private Double lastInheritedRiskScore;
293293

294+
/**
295+
* Convenience field which will contain the date of the last vulnerability analysis of the {@link Bom} components
296+
*/
297+
@Persistent
298+
@Column(name = "LAST_VULNERABILITY_ANALYSIS", allowsNull = "true")
299+
@Schema(type = "integer", format = "int64", requiredMode = Schema.RequiredMode.NOT_REQUIRED, description = "UNIX epoch timestamp in milliseconds")
300+
private Date lastVulnerabilityAnalysis;
301+
294302
@Persistent
295303
@Column(name = "ACTIVE", defaultValue = "true")
296304
@JsonSerialize(nullsUsing = BooleanDefaultTrueSerializer.class)
@@ -540,6 +548,14 @@ public void setLastBomImportFormat(String lastBomImportFormat) {
540548
this.lastBomImportFormat = lastBomImportFormat;
541549
}
542550

551+
public Date getLastVulnerabilityAnalysis() {
552+
return lastVulnerabilityAnalysis;
553+
}
554+
555+
public void setLastVulnerabilityAnalysis(Date lastVulnerabilityAnalysis) {
556+
this.lastVulnerabilityAnalysis = lastVulnerabilityAnalysis;
557+
}
558+
543559
public Double getLastInheritedRiskScore() {
544560
return lastInheritedRiskScore;
545561
}

src/main/java/org/dependencytrack/tasks/VulnerabilityAnalysisTask.java

+3
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import javax.jdo.Query;
5353
import java.util.ArrayList;
5454
import java.util.Collection;
55+
import java.util.Date;
5556
import java.util.HashMap;
5657
import java.util.List;
5758
import java.util.UUID;
@@ -178,6 +179,8 @@ private void analyzeProject(
178179
qm.getPersistenceManager().evictAll(false, Component.class);
179180
components = fetchNextComponentBatch(qm, project, components.getLast().getId());
180181
}
182+
183+
project.setLastVulnerabilityAnalysis(new Date());
181184
} finally {
182185
projectLock.unlock();
183186
}

src/test/java/org/dependencytrack/tasks/VulnerabilityAnalysisTaskTest.java

+2
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ public void shouldAnalyzeProject() {
160160
// For analysis of individual projects, metrics updates are expected to
161161
// be initiated via event chaining.
162162
assertThat(EVENTS).isEmpty();
163+
164+
assertThat(qm.getProject("acme-lib", "2.0.0").getLastVulnerabilityAnalysis()).isNotNull();
163165
}
164166

165167
@Test

0 commit comments

Comments
 (0)