|
27 | 27 |
|
28 | 28 | public class AemCloudValidator implements NodePathValidator { |
29 | 29 |
|
30 | | - static final String VIOLATION_MESSAGE_STRING = "Using nodes below /var is only allowed in author-specific packages. Further details at https://experienceleague.adobe.com/docs/experience-manager-learn/cloud-service/debugging/debugging-aem-as-a-cloud-service/build-and-deployment.html?lang=en#including-%2Fvar-in-content-package"; |
| 30 | + static final String VIOLATION_MESSAGE_STRING_VAR_NODES_CONDITION_CONTAINER = "only allowed in author-specific packages"; |
| 31 | + static final String VIOLATION_MESSAGE_STRING_VAR_NODES_CONDITION_OVERALL = "not allowed"; |
| 32 | + static final String VIOLATION_MESSAGE_STRING_VAR_NODES = "Using nodes below /var is %s. Consider to use repoinit scripts instead or move that content to another location. Further details at https://experienceleague.adobe.com/docs/experience-manager-learn/cloud-service/debugging/debugging-aem-as-a-cloud-service/build-and-deployment.html?lang=en#including-%%2Fvar-in-content-package"; |
31 | 33 |
|
32 | 34 | private final @NotNull ValidationMessageSeverity defaultSeverity; |
33 | 35 | private final ValidationContext containerValidationContext; |
34 | 36 | private boolean foundViolation; |
35 | 37 |
|
36 | | - public AemCloudValidator(@Nullable ValidationContext containerValidationContext, @NotNull ValidationMessageSeverity defaultSeverity) { |
| 38 | + private boolean allowVarNodesOutsideContainers; |
| 39 | + |
| 40 | + public AemCloudValidator(boolean allowVarNodesOutsideContainers, @Nullable ValidationContext containerValidationContext, @NotNull ValidationMessageSeverity defaultSeverity) { |
37 | 41 | super(); |
38 | 42 | this.containerValidationContext = containerValidationContext; |
39 | 43 | this.defaultSeverity = defaultSeverity; |
40 | 44 | this.foundViolation = false; |
| 45 | + this.allowVarNodesOutsideContainers = allowVarNodesOutsideContainers; |
41 | 46 | } |
42 | 47 |
|
43 | 48 | @Override |
44 | 49 | public Collection<ValidationMessage> validate(@NotNull String path) { |
45 | | - // only check if within a container |
46 | | - if (containerValidationContext != null && !foundViolation) { |
| 50 | + if (!foundViolation && path.startsWith("/var/")) { |
47 | 51 | // check if package itself is only used on author |
48 | | - if (path.startsWith("/var/") && !isContainedInAuthorOnlyPackage(containerValidationContext)) { |
| 52 | + if (!allowVarNodesOutsideContainers || !isContainedInAuthorOnlyPackage(containerValidationContext)) { |
49 | 53 | // only emit once per package |
50 | 54 | foundViolation = true; |
51 | | - return Collections.singleton(new ValidationMessage(defaultSeverity, VIOLATION_MESSAGE_STRING)); |
| 55 | + return Collections.singleton(new ValidationMessage(defaultSeverity, String.format( |
| 56 | + VIOLATION_MESSAGE_STRING_VAR_NODES, allowVarNodesOutsideContainers ? VIOLATION_MESSAGE_STRING_VAR_NODES_CONDITION_CONTAINER : VIOLATION_MESSAGE_STRING_VAR_NODES_CONDITION_OVERALL))); |
52 | 57 | } |
53 | 58 | } |
54 | 59 | return null; |
|
0 commit comments