DependencyValidator implements PropertiesValidator { @Override public Collection<ValidationMessage> validate(@NotNull PackageProperties properties) { Collection<ValidationMessage> messages = new LinkedList<>(); Map<String, PackageInfo> roots = new HashMap<>(); for (Dependency dependency : properties.getDependencies()) { boolean isDependencyResolved = false; for (PackageInfo resolvedDependency : dependenciesMetaInfo) { if (dependency.matches(resolvedDependency.getId())) { for (PathFilterSet set : resolvedDependency.getFilter().getFilterSets()) { String root = set.getRoot(); PackageInfo existing = roots.get(root); if (existing != null) { String msg = String.format(MESSAGE_DEPENDENCIES_WITH_OVERLAPPING_FILTERS, resolvedDependency.getId(), root, existing.getId()); messages.add(new ValidationMessage(severity, msg)); } roots.put(root, resolvedDependency); } isDependencyResolved = true; break; } } if (!isDependencyResolved) { String msg = String.format(MESSAGE_UNRESOLVED_DEPENDENCY, dependency); messages.add(new ValidationMessage(severityForUnresolvedDependencies, msg)); continue; } } return messages; } DependencyValidator(@NotNull ValidationMessageSeverity severity, ValidationMessageSeverity severityForUnresolvedDependencies, Collection<PackageInfo> dependenciesMetaInfo); @Override Collection<ValidationMessage> done(); @Override Collection<ValidationMessage> validate(@NotNull PackageProperties properties);  }
@Test public void testWithResolvedNonOverlappingDependency() { resolvedPackageInfos.add(getPackageInfo("group1:package1:0.1", "/filter.xml", null)); resolvedPackageInfos.add(getPackageInfo("group2:package2:2.9", "/simple-package/META-INF/vault/filter.xml", null)); Assert.assertThat(validator.validate(properties), AnyValidationMessageMatcher.noValidationInCollection()); }
@Test public void testValidateWithUnresolvedDependencies() { resolvedPackageInfos.add(getPackageInfo("group1:package1:0.1", "/filter.xml", null)); Assert.assertThat(validator.validate(properties), Matchers.contains(new ValidationMessage(ValidationMessageSeverity.ERROR, String.format(String.format(DependencyValidator.MESSAGE_UNRESOLVED_DEPENDENCY, "group2:package2:(2,3)"))))); }
@Test public void testValidateWithDependenciesWithOverlappingFilterRoots() { resolvedPackageInfos.add(getPackageInfo("group1:package1:0.1", "/simple-package/META-INF/vault/filter.xml", null)); resolvedPackageInfos.add(getPackageInfo("group2:package2:2.9", "/simple-package/META-INF/vault/filter.xml", null)); Assert.assertThat(validator.validate(properties), Matchers.contains(new ValidationMessage(ValidationMessageSeverity.ERROR, String.format(String.format(String.format(DependencyValidator.MESSAGE_DEPENDENCIES_WITH_OVERLAPPING_FILTERS, "group2:package2:2.9", "/etc/project1", "group1:package1:0.1")))))); }