-
Notifications
You must be signed in to change notification settings - Fork 1
/
LicenseFileValidator.java
49 lines (43 loc) · 1.79 KB
/
LicenseFileValidator.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
49
package com.exasol.projectkeeper.validators;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.util.*;
import com.exasol.errorreporting.ExaError;
import com.exasol.projectkeeper.validators.finding.ValidationFinding;
/**
* This is a {@link com.exasol.projectkeeper.Validator} for the LICENSE file.
* <p>
* We implemented this validator in Java and not just as a file in the template resources, since it requires the current
* year as parameter.
* </p>
*/
//[impl->dsn~license-file-validator~1]
public class LicenseFileValidator extends AbstractFileContentValidator {
/**
* Create a new instance of {@link LicenseFileValidator}.
*
* @param projectDirectory project's root directory
*/
public LicenseFileValidator(final Path projectDirectory) {
super(projectDirectory, Path.of("LICENSE"));
}
@Override
protected List<ValidationFinding> validateContent(final String content) {
return Collections.emptyList();
}
@Override
protected String getTemplate() {
final Calendar calendar = Calendar.getInstance();
return getTemplateFromResources().replace("!!!YEAR!!!", String.valueOf(calendar.get(Calendar.YEAR)));
}
private String getTemplateFromResources() {
try (final InputStream templateStream = getClass().getClassLoader().getResourceAsStream("LICENSE-template")) {
return new String(templateStream.readAllBytes(), StandardCharsets.UTF_8);
} catch (final IOException | NullPointerException exception) {
throw new IllegalStateException(ExaError.messageBuilder("F-PK-CORE-68")
.message("Failed to open LICENSE file template.").ticketMitigation().toString(), exception);
}
}
}