public static void addDependencies()

in tooling/camel-kafka-connector-generator-maven-plugin/src/main/java/org/apache/camel/kafkaconnector/maven/utils/MavenUtils.java [181:220]


    public static void addDependencies(Document pom, Set<String> deps, String generatedSectionStartMarker, String generatedSectionStopMarker) throws XPathExpressionException {
        XPath xpath = XPathFactory.newInstance().newXPath();
        Node dependencies = ((NodeList) xpath.compile("/project/dependencies").evaluate(pom, XPathConstants.NODESET)).item(0);

        if (!deps.isEmpty()) {
            dependencies.appendChild(pom.createComment(generatedSectionStartMarker));
            for (String dep : deps) {
                Element dependency = pom.createElement("dependency");
                dependencies.appendChild(dependency);

                String[] comps = dep.split("\\:");
                String groupIdStr = comps[0];
                String artifactIdStr = comps[1];
                String versionStr = comps.length > 2 && !comps[2].isEmpty() ? comps[2] : null;
                String scopeStr = comps.length > 3 ? comps[3] : null;

                Element groupId = pom.createElement("groupId");
                groupId.setTextContent(groupIdStr);
                dependency.appendChild(groupId);

                Element artifactId = pom.createElement("artifactId");
                artifactId.setTextContent(artifactIdStr);
                dependency.appendChild(artifactId);

                if (versionStr != null) {
                    Element version = pom.createElement("version");
                    version.setTextContent(versionStr);
                    dependency.appendChild(version);
                }

                if (scopeStr != null) {
                    Element scope = pom.createElement("scope");
                    scope.setTextContent(scopeStr);
                    dependency.appendChild(scope);
                }

            }
            dependencies.appendChild(pom.createComment(generatedSectionStopMarker));
        }
    }