Skip to content

Commit d382d88

Browse files
committed
Add logic to populate last modified date after resolving artifact
1 parent f8b878d commit d382d88

3 files changed

Lines changed: 12 additions & 7 deletions

File tree

core/src/main/java/io/snyk/plugins/artifactory/model/MonitoredArtifact.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class MonitoredArtifact {
2222

2323
private final Ignores ignores;
2424

25-
private final Instant lastModifiedDate;
25+
private Instant lastModifiedDate;
2626

2727
public MonitoredArtifact(String path, TestResult testResult, Ignores ignores) {
2828
this(path, testResult, ignores, null);
@@ -51,6 +51,10 @@ public Optional<Instant> getLastModifiedDate() {
5151
return Optional.ofNullable(lastModifiedDate);
5252
}
5353

54+
public void setLastModifiedDate(Instant lastModifiedDate) {
55+
this.lastModifiedDate = lastModifiedDate;
56+
}
57+
5458
public MonitoredArtifact write(ArtifactProperties properties) {
5559
testResult.write(properties);
5660

core/src/main/java/io/snyk/plugins/artifactory/scanner/PackageValidator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ public void validate(MonitoredArtifact artifact) {
3333
private void validateLastModifiedDelay(MonitoredArtifact artifact) {
3434
Integer delayDays = settings.getLastModifiedDelayDays().get();
3535
if (delayDays == null || delayDays <= 0) {
36-
LOG.debug("Created delay is disabled ({} days)", delayDays);
36+
LOG.debug("Last modifed date delay is disabled ({} days)", delayDays);
3737
return;
3838
}
3939

4040
Optional<Instant> lastModifiedDate = artifact.getLastModifiedDate();
4141
if (lastModifiedDate.isEmpty()) {
42-
LOG.debug("Created date not available for {}, skipping created delay check", artifact.getPath());
42+
LOG.debug("Last modified date not available for {}, skipping created delay check", artifact.getPath());
4343
return;
4444
}
4545

core/src/main/java/io/snyk/plugins/artifactory/scanner/ScannerModule.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,10 @@ public void filterAccess(@Nonnull RepoPath repoPath) {
7070
}
7171

7272
private Optional<MonitoredArtifact> resolveArtifact(RepoPath repoPath) {
73-
return artifactResolver.get(properties(repoPath), () -> runTest(repoPath));
73+
Optional<MonitoredArtifact> monitoredArtifact = artifactResolver.get(properties(repoPath), () -> runTest(repoPath));
74+
Instant lastModifiedDate = getLastModifiedDate(repoPath);
75+
monitoredArtifact.ifPresent(artifact -> artifact.setLastModifiedDate(lastModifiedDate));
76+
return monitoredArtifact;
7477
}
7578

7679
private ArtifactProperties properties(RepoPath repoPath) {
@@ -98,8 +101,6 @@ private void filter(MonitoredArtifact artifact) {
98101
private @NotNull MonitoredArtifact toMonitoredArtifact(TestResult testResult, @NotNull RepoPath repoPath) {
99102
Ignores ignores = Ignores.read(new RepositoryArtifactProperties(repoPath, repositories));
100103
Instant lastModifiedDate = getLastModifiedDate(repoPath);
101-
102-
LOG.debug("Retrieved last modified date of {} for {}", lastModifiedDate, repoPath);
103104

104105
// Only apply lastModifiedDate to packages from remote repositories.
105106
if(lastModifiedDateRemoteOnly()) {
@@ -117,7 +118,7 @@ private Instant getLastModifiedDate(RepoPath repoPath) {
117118
ItemInfo itemInfo = repositories.getItemInfo(repoPath);
118119
if (itemInfo != null) {
119120
Instant lastModified = Instant.ofEpochMilli(itemInfo.getLastModified());
120-
LOG.debug("Retrieved last modifed date of {}", lastModified.toString());
121+
LOG.debug("Retrieved last modified date of {} for {}", lastModified, repoPath);
121122
return lastModified;
122123
} else {
123124
LOG.debug("Unable to retrieve ItemInfo for {}, could not retrieve last modified date", repoPath);

0 commit comments

Comments
 (0)