Skip to content

Commit eeb7ce1

Browse files
authored
optionally enable check for /var nodes even outside container packages (#2)
1 parent fc70bfc commit eeb7ce1

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ Validates content packages for invalid usage patterns described in [Debugging AE
99

1010
*This validator only includes checks which are not yet covered by the [aem-analyser-maven-plugin][aem-analyser-maven-plugin] so it is strongly recommended to also enable the [aem-analyser-maven-plugin][aem-analyser-maven-plugin] in your build.*
1111

12+
# Settings
13+
14+
The following options are supported apart from the default settings mentioned in [FileVault validation][2].
15+
16+
Option | Mandatory | Description
17+
--- | --- | ---
18+
allowVarNodeOutsideContainer | no | `true` in case `/var` nodes should be allowed in content packages which do not contain other packages (i.e. are no containers). Otherwise `var` nodes are not even allowed in standalone packages. Default value `true`.
19+
1220
# Included Checks
1321

1422
## Including `/var` in content package

src/main/java/biz/netcentric/filevault/validator/aem/cloud/AemCloudValidator.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,28 +27,33 @@
2727

2828
public class AemCloudValidator implements NodePathValidator {
2929

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";
3133

3234
private final @NotNull ValidationMessageSeverity defaultSeverity;
3335
private final ValidationContext containerValidationContext;
3436
private boolean foundViolation;
3537

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) {
3741
super();
3842
this.containerValidationContext = containerValidationContext;
3943
this.defaultSeverity = defaultSeverity;
4044
this.foundViolation = false;
45+
this.allowVarNodesOutsideContainers = allowVarNodesOutsideContainers;
4146
}
4247

4348
@Override
4449
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/")) {
4751
// check if package itself is only used on author
48-
if (path.startsWith("/var/") && !isContainedInAuthorOnlyPackage(containerValidationContext)) {
52+
if (!allowVarNodesOutsideContainers || !isContainedInAuthorOnlyPackage(containerValidationContext)) {
4953
// only emit once per package
5054
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)));
5257
}
5358
}
5459
return null;

src/main/java/biz/netcentric/filevault/validator/aem/cloud/AemCloudValidatorFactory.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,25 @@
1919
import org.apache.jackrabbit.vault.validation.spi.ValidatorSettings;
2020
import org.jetbrains.annotations.NotNull;
2121
import org.kohsuke.MetaInfServices;
22+
import org.slf4j.Logger;
23+
import org.slf4j.LoggerFactory;
24+
2225

2326
@MetaInfServices
2427
public class AemCloudValidatorFactory implements ValidatorFactory {
2528

29+
private static final Logger LOGGER = LoggerFactory.getLogger(AemCloudValidatorFactory.class);
30+
31+
private static final String OPTION_ALLOW_VAR_NODE_OUTSIDE_CONTAINERS = "allowVarNodeOutsideContainer";
32+
2633
@Override
2734
public Validator createValidator(@NotNull ValidationContext context, @NotNull ValidatorSettings settings) {
28-
return new AemCloudValidator(context.getContainerValidationContext(), settings.getDefaultSeverity());
35+
boolean allowVarNodesOutsideContainers = true;
36+
if (settings.getOptions().containsKey(OPTION_ALLOW_VAR_NODE_OUTSIDE_CONTAINERS)) {
37+
allowVarNodesOutsideContainers = Boolean.parseBoolean(settings.getOptions().get(OPTION_ALLOW_VAR_NODE_OUTSIDE_CONTAINERS));
38+
}
39+
LOGGER.debug("netcentric-aem-cloud: Allow /var nodes outside containers: {}", allowVarNodesOutsideContainers);
40+
return new AemCloudValidator(allowVarNodesOutsideContainers, context.getContainerValidationContext(), settings.getDefaultSeverity());
2941
}
3042

3143
@Override

0 commit comments

Comments
 (0)