-
Notifications
You must be signed in to change notification settings - Fork 1
/
LatestChangesFileValidator.java
48 lines (43 loc) · 1.9 KB
/
LatestChangesFileValidator.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package com.exasol.projectkeeper.validators.files;
import java.nio.file.Path;
import java.util.Collections;
import java.util.List;
import com.exasol.errorreporting.ExaError;
import com.exasol.projectkeeper.Validator;
import com.exasol.projectkeeper.validators.VersionCollector;
import com.exasol.projectkeeper.validators.changesfile.ChangesFileName;
import com.exasol.projectkeeper.validators.finding.SimpleValidationFinding;
import com.exasol.projectkeeper.validators.finding.ValidationFinding;
/**
* Ensure there is no newer changes file than that for the current version of the current project.
*/
public class LatestChangesFileValidator implements Validator {
final Path projectDirectory;
final String projectVersion;
/**
* Create a new instance of {@link LatestChangesFileValidator}.
*
* @param projectDir project's root directory
* @param projectVersion version of the project to validate
*/
public LatestChangesFileValidator(final Path projectDir, final String projectVersion) {
this.projectDirectory = projectDir;
this.projectVersion = projectVersion;
}
@Override
public List<ValidationFinding> validate() {
final List<ValidationFinding> empty = Collections.emptyList();
final List<ChangesFileName> list = new VersionCollector(this.projectDirectory).collectChangesFiles();
if (list.isEmpty()) {
return empty;
}
final ChangesFileName latest = list.get(0);
if (latest.version().equals(this.projectVersion)) {
return empty;
}
return List.of(SimpleValidationFinding.withMessage(ExaError.messageBuilder("E-PK-CORE-162")
.message("Found newer changes file {{filename}}.", latest.filename())
.mitigation("Please remove changes file later than current version {{version}}.", this.projectVersion) //
.toString()).build());
}
}