@Test public void testApplicationPackageTypeWithAllowedComplexFilters() throws IOException, ConfigurationException { validator = new PackageTypeValidator(filter, ValidationMessageSeverity.ERROR, ValidationMessageSeverity.WARN, ValidationMessageSeverity.INFO, false, false, true, PackageType.APPLICATION, PackageTypeValidatorFactory.DEFAULT_JCR_INSTALLER_NODE_PATH_REGEX, PackageTypeValidatorFactory.DEFAULT_ADDITIONAL_JCR_INSTALLER_FILE_NODE_PATH_REGEX, null); DefaultWorkspaceFilter filter = new DefaultWorkspaceFilter(); try (InputStream input = this.getClass().getResourceAsStream("/filter.xml")) { filter.load(input); } Assert.assertThat(validator.validate(filter), AnyValidationMessageMatcher.noValidationInCollection()); }
@Override public @Nullable Collection<ValidationMessage> validate(@NotNull NodeContext nodeContext) { if (!filter.covers(nodeContext.getNodePath())) { return null; } Collection<ValidationMessage> messages = new LinkedList<>(); switch (type) { case CONTENT: if (isAppContent(nodeContext.getNodePath())) { messages.add(new ValidationMessage(severity, String.format(MESSAGE_APP_CONTENT, type))); } if (isOsgiBundleOrConfiguration(nodeContext.getNodePath(), true)) { messages.add(new ValidationMessage(severity, String.format(MESSAGE_OSGI_BUNDLE_OR_CONFIG, type))); } break; case APPLICATION: if (!isAppContent(nodeContext.getNodePath())) { messages.add(new ValidationMessage(severity, String.format(MESSAGE_NO_APP_CONTENT_FOUND, type))); } if (isOsgiBundleOrConfiguration(nodeContext.getNodePath(), true)) { messages.add(new ValidationMessage(severity, String.format(MESSAGE_OSGI_BUNDLE_OR_CONFIG, type))); } break; case CONTAINER: if (isOsgiBundleOrConfiguration(nodeContext.getNodePath(), false)) { validContainerNodePaths.add(nodeContext.getNodePath()); } else if (isSubPackage(nodeContext.getNodePath())) { validContainerNodePaths.add(nodeContext.getNodePath()); } else { potentiallyDisallowedContainerNodes.add(nodeContext); } break; case MIXED: break; } return messages; }
PackageTypeValidator implements NodePathValidator, FilterValidator, PropertiesValidator, MetaInfPathValidator, DocumentViewXmlValidator { @Override public @Nullable Collection<ValidationMessage> validate(@NotNull NodeContext nodeContext) { if (!filter.covers(nodeContext.getNodePath())) { return null; } Collection<ValidationMessage> messages = new LinkedList<>(); switch (type) { case CONTENT: if (isAppContent(nodeContext.getNodePath())) { messages.add(new ValidationMessage(severity, String.format(MESSAGE_APP_CONTENT, type))); } if (isOsgiBundleOrConfiguration(nodeContext.getNodePath(), true)) { messages.add(new ValidationMessage(severity, String.format(MESSAGE_OSGI_BUNDLE_OR_CONFIG, type))); } break; case APPLICATION: if (!isAppContent(nodeContext.getNodePath())) { messages.add(new ValidationMessage(severity, String.format(MESSAGE_NO_APP_CONTENT_FOUND, type))); } if (isOsgiBundleOrConfiguration(nodeContext.getNodePath(), true)) { messages.add(new ValidationMessage(severity, String.format(MESSAGE_OSGI_BUNDLE_OR_CONFIG, type))); } break; case CONTAINER: if (isOsgiBundleOrConfiguration(nodeContext.getNodePath(), false)) { validContainerNodePaths.add(nodeContext.getNodePath()); } else if (isSubPackage(nodeContext.getNodePath())) { validContainerNodePaths.add(nodeContext.getNodePath()); } else { potentiallyDisallowedContainerNodes.add(nodeContext); } break; case MIXED: break; } return messages; } }
PackageTypeValidator implements NodePathValidator, FilterValidator, PropertiesValidator, MetaInfPathValidator, DocumentViewXmlValidator { @Override public @Nullable Collection<ValidationMessage> validate(@NotNull NodeContext nodeContext) { if (!filter.covers(nodeContext.getNodePath())) { return null; } Collection<ValidationMessage> messages = new LinkedList<>(); switch (type) { case CONTENT: if (isAppContent(nodeContext.getNodePath())) { messages.add(new ValidationMessage(severity, String.format(MESSAGE_APP_CONTENT, type))); } if (isOsgiBundleOrConfiguration(nodeContext.getNodePath(), true)) { messages.add(new ValidationMessage(severity, String.format(MESSAGE_OSGI_BUNDLE_OR_CONFIG, type))); } break; case APPLICATION: if (!isAppContent(nodeContext.getNodePath())) { messages.add(new ValidationMessage(severity, String.format(MESSAGE_NO_APP_CONTENT_FOUND, type))); } if (isOsgiBundleOrConfiguration(nodeContext.getNodePath(), true)) { messages.add(new ValidationMessage(severity, String.format(MESSAGE_OSGI_BUNDLE_OR_CONFIG, type))); } break; case CONTAINER: if (isOsgiBundleOrConfiguration(nodeContext.getNodePath(), false)) { validContainerNodePaths.add(nodeContext.getNodePath()); } else if (isSubPackage(nodeContext.getNodePath())) { validContainerNodePaths.add(nodeContext.getNodePath()); } else { potentiallyDisallowedContainerNodes.add(nodeContext); } break; case MIXED: break; } return messages; } PackageTypeValidator(@NotNull WorkspaceFilter workspaceFilter, @NotNull ValidationMessageSeverity severity,
            @NotNull ValidationMessageSeverity severityForNoPackageType, @NotNull ValidationMessageSeverity severityForLegacyType,
            boolean prohibitMutableContent, boolean prohibitImmutableContent, boolean allowComplexFilterRulesInApplicationPackages,
            @NotNull PackageType type, @NotNull Pattern jcrInstallerNodePathRegex, @NotNull Pattern additionalJcrInstallerFileNodePathRegex,
            @Nullable ValidationContext containerValidationContext); }
PackageTypeValidator implements NodePathValidator, FilterValidator, PropertiesValidator, MetaInfPathValidator, DocumentViewXmlValidator { @Override public @Nullable Collection<ValidationMessage> validate(@NotNull NodeContext nodeContext) { if (!filter.covers(nodeContext.getNodePath())) { return null; } Collection<ValidationMessage> messages = new LinkedList<>(); switch (type) { case CONTENT: if (isAppContent(nodeContext.getNodePath())) { messages.add(new ValidationMessage(severity, String.format(MESSAGE_APP_CONTENT, type))); } if (isOsgiBundleOrConfiguration(nodeContext.getNodePath(), true)) { messages.add(new ValidationMessage(severity, String.format(MESSAGE_OSGI_BUNDLE_OR_CONFIG, type))); } break; case APPLICATION: if (!isAppContent(nodeContext.getNodePath())) { messages.add(new ValidationMessage(severity, String.format(MESSAGE_NO_APP_CONTENT_FOUND, type))); } if (isOsgiBundleOrConfiguration(nodeContext.getNodePath(), true)) { messages.add(new ValidationMessage(severity, String.format(MESSAGE_OSGI_BUNDLE_OR_CONFIG, type))); } break; case CONTAINER: if (isOsgiBundleOrConfiguration(nodeContext.getNodePath(), false)) { validContainerNodePaths.add(nodeContext.getNodePath()); } else if (isSubPackage(nodeContext.getNodePath())) { validContainerNodePaths.add(nodeContext.getNodePath()); } else { potentiallyDisallowedContainerNodes.add(nodeContext); } break; case MIXED: break; } return messages; } PackageTypeValidator(@NotNull WorkspaceFilter workspaceFilter, @NotNull ValidationMessageSeverity severity,
            @NotNull ValidationMessageSeverity severityForNoPackageType, @NotNull ValidationMessageSeverity severityForLegacyType,
            boolean prohibitMutableContent, boolean prohibitImmutableContent, boolean allowComplexFilterRulesInApplicationPackages,
            @NotNull PackageType type, @NotNull Pattern jcrInstallerNodePathRegex, @NotNull Pattern additionalJcrInstallerFileNodePathRegex,
            @Nullable ValidationContext containerValidationContext); @Override @Nullable Collection<ValidationMessage> done(); @Override @Nullable Collection<ValidationMessage> validate(@NotNull NodeContext nodeContext); @Override Collection<ValidationMessage> validate(@NotNull WorkspaceFilter filter); @Override Collection<ValidationMessage> validate(@NotNull PackageProperties properties); @Override Collection<ValidationMessage> validateMetaInfPath(@NotNull Path filePath, @NotNull Path basePath, boolean isFolder); @Override @Nullable Collection<ValidationMessage> validate(@NotNull DocViewNode node, @NotNull String nodePath,
            @NotNull Path filePath, boolean isRoot); }
PackageTypeValidator implements NodePathValidator, FilterValidator, PropertiesValidator, MetaInfPathValidator, DocumentViewXmlValidator { @Override public @Nullable Collection<ValidationMessage> validate(@NotNull NodeContext nodeContext) { if (!filter.covers(nodeContext.getNodePath())) { return null; } Collection<ValidationMessage> messages = new LinkedList<>(); switch (type) { case CONTENT: if (isAppContent(nodeContext.getNodePath())) { messages.add(new ValidationMessage(severity, String.format(MESSAGE_APP_CONTENT, type))); } if (isOsgiBundleOrConfiguration(nodeContext.getNodePath(), true)) { messages.add(new ValidationMessage(severity, String.format(MESSAGE_OSGI_BUNDLE_OR_CONFIG, type))); } break; case APPLICATION: if (!isAppContent(nodeContext.getNodePath())) { messages.add(new ValidationMessage(severity, String.format(MESSAGE_NO_APP_CONTENT_FOUND, type))); } if (isOsgiBundleOrConfiguration(nodeContext.getNodePath(), true)) { messages.add(new ValidationMessage(severity, String.format(MESSAGE_OSGI_BUNDLE_OR_CONFIG, type))); } break; case CONTAINER: if (isOsgiBundleOrConfiguration(nodeContext.getNodePath(), false)) { validContainerNodePaths.add(nodeContext.getNodePath()); } else if (isSubPackage(nodeContext.getNodePath())) { validContainerNodePaths.add(nodeContext.getNodePath()); } else { potentiallyDisallowedContainerNodes.add(nodeContext); } break; case MIXED: break; } return messages; } PackageTypeValidator(@NotNull WorkspaceFilter workspaceFilter, @NotNull ValidationMessageSeverity severity,
            @NotNull ValidationMessageSeverity severityForNoPackageType, @NotNull ValidationMessageSeverity severityForLegacyType,
            boolean prohibitMutableContent, boolean prohibitImmutableContent, boolean allowComplexFilterRulesInApplicationPackages,
            @NotNull PackageType type, @NotNull Pattern jcrInstallerNodePathRegex, @NotNull Pattern additionalJcrInstallerFileNodePathRegex,
            @Nullable ValidationContext containerValidationContext); @Override @Nullable Collection<ValidationMessage> done(); @Override @Nullable Collection<ValidationMessage> validate(@NotNull NodeContext nodeContext); @Override Collection<ValidationMessage> validate(@NotNull WorkspaceFilter filter); @Override Collection<ValidationMessage> validate(@NotNull PackageProperties properties); @Override Collection<ValidationMessage> validateMetaInfPath(@NotNull Path filePath, @NotNull Path basePath, boolean isFolder); @Override @Nullable Collection<ValidationMessage> validate(@NotNull DocViewNode node, @NotNull String nodePath,
            @NotNull Path filePath, boolean isRoot);  }