diff options
author | Bjørn Christian Seime <bjorncs@verizonmedia.com> | 2022-01-18 16:00:41 +0100 |
---|---|---|
committer | Bjørn Christian Seime <bjorncs@verizonmedia.com> | 2022-01-18 16:00:41 +0100 |
commit | 6de3a640675601bfaf33d1a0bf01358fdbb5990b (patch) | |
tree | 4be9353aad7a73304e33fa3dd0534dee641ff39b | |
parent | 7c1a1dac865dfe2289799192827d36f5c247e4ef (diff) |
Add helper method to iterate over sub-elements
-rw-r--r-- | config-model/src/main/java/com/yahoo/vespa/model/application/validation/BundleValidator.java | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/application/validation/BundleValidator.java b/config-model/src/main/java/com/yahoo/vespa/model/application/validation/BundleValidator.java index 1ca8e82aea6..474043548db 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/application/validation/BundleValidator.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/application/validation/BundleValidator.java @@ -32,6 +32,7 @@ import java.util.List; import java.util.Map; import java.util.Optional; import java.util.Set; +import java.util.function.Consumer; import java.util.function.Predicate; import java.util.jar.Attributes; import java.util.jar.JarFile; @@ -164,11 +165,7 @@ public class BundleValidator extends Validator { } private static void validateDependencies(DeployLogger deployLogger, String jarFilename, Document pom) throws XPathExpressionException { - NodeList dependencies = (NodeList) XPathFactory.newDefaultInstance().newXPath() - .compile("/project/dependencies/dependency") - .evaluate(pom, XPathConstants.NODESET); - for (int i = 0; i < dependencies.getLength(); i++) { - Element dependency = (Element) dependencies.item(i); + forEachPomXmlElement(pom, "dependencies/dependency", dependency -> { String groupId = dependency.getElementsByTagName("groupId").item(0).getTextContent(); String artifactId = dependency.getElementsByTagName("artifactId").item(0).getTextContent(); for (DeprecatedMavenArtifact deprecatedArtifact : DeprecatedMavenArtifact.values()) { @@ -179,6 +176,16 @@ public class BundleValidator extends Validator { jarFilename, groupId, artifactId, deprecatedArtifact.description)); } } + }); + } + + private static void forEachPomXmlElement(Document pom, String xpath, Consumer<Element> consumer) throws XPathExpressionException { + NodeList dependencies = (NodeList) XPathFactory.newDefaultInstance().newXPath() + .compile("/project/" + xpath) + .evaluate(pom, XPathConstants.NODESET); + for (int i = 0; i < dependencies.getLength(); i++) { + Element element = (Element) dependencies.item(i); + consumer.accept(element); } } |