diff --git a/modules/services/event-history-service/pom.xml b/modules/services/event-history-service/pom.xml index 6733b988..b1483ca3 100644 --- a/modules/services/event-history-service/pom.xml +++ b/modules/services/event-history-service/pom.xml @@ -32,10 +32,6 @@ org.apache.kafka kafka-clients - - com.taosdata.jdbc - taos-jdbcdriver - org.springframework.boot spring-boot-starter-web diff --git a/modules/services/event-history-service/src/test/java/com/lingniu/ingest/eventhistory/config/EventHistoryPomBoundaryTest.java b/modules/services/event-history-service/src/test/java/com/lingniu/ingest/eventhistory/config/EventHistoryPomBoundaryTest.java new file mode 100644 index 00000000..96e79384 --- /dev/null +++ b/modules/services/event-history-service/src/test/java/com/lingniu/ingest/eventhistory/config/EventHistoryPomBoundaryTest.java @@ -0,0 +1,71 @@ +package com.lingniu.ingest.eventhistory.config; + +import org.junit.jupiter.api.Test; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +import javax.xml.parsers.DocumentBuilderFactory; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; + +class EventHistoryPomBoundaryTest { + + @Test + void tdengineJdbcDriverIsOwnedByTdengineHistoryStoreModule() throws Exception { + assertThat(directDependencies(modulePom())) + .doesNotContain("com.taosdata.jdbc:taos-jdbcdriver"); + } + + private static Document modulePom() throws Exception { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); + return factory.newDocumentBuilder().parse(Files.newInputStream(repositoryRoot() + .resolve("modules/services/event-history-service/pom.xml"))); + } + + private static List directDependencies(Document pom) { + Element dependencies = firstDirectChild(pom.getDocumentElement(), "dependencies"); + if (dependencies == null) { + return List.of(); + } + List coordinates = new ArrayList<>(); + NodeList children = dependencies.getChildNodes(); + for (int i = 0; i < children.getLength(); i++) { + if (!(children.item(i) instanceof Element dependency) || !"dependency".equals(dependency.getTagName())) { + continue; + } + Element groupId = firstDirectChild(dependency, "groupId"); + Element artifactId = firstDirectChild(dependency, "artifactId"); + if (groupId != null && artifactId != null) { + coordinates.add(groupId.getTextContent().trim() + ":" + artifactId.getTextContent().trim()); + } + } + return List.copyOf(coordinates); + } + + private static Element firstDirectChild(Element parent, String tagName) { + NodeList children = parent.getChildNodes(); + for (int i = 0; i < children.getLength(); i++) { + if (children.item(i) instanceof Element child && tagName.equals(child.getTagName())) { + return child; + } + } + return null; + } + + private static Path repositoryRoot() { + Path current = Path.of(System.getProperty("user.dir")).toAbsolutePath(); + while (current != null) { + if (Files.exists(current.resolve("pom.xml")) && Files.exists(current.resolve("modules"))) { + return current; + } + current = current.getParent(); + } + throw new IllegalStateException("repository root not found"); + } +}