From ba1ec9a012ed4375db2ff102caa7bfd9b1833c7d Mon Sep 17 00:00:00 2001 From: lingniu Date: Wed, 1 Jul 2026 09:42:15 +0800 Subject: [PATCH] build: scope optional module versions to profiles --- .../historyapp/MavenModuleProfileTest.java | 81 ++++++++++++++++++- pom.xml | 80 +++++++++++------- 2 files changed, 128 insertions(+), 33 deletions(-) diff --git a/modules/apps/vehicle-history-app/src/test/java/com/lingniu/ingest/historyapp/MavenModuleProfileTest.java b/modules/apps/vehicle-history-app/src/test/java/com/lingniu/ingest/historyapp/MavenModuleProfileTest.java index c8d8740c..d4fa8568 100644 --- a/modules/apps/vehicle-history-app/src/test/java/com/lingniu/ingest/historyapp/MavenModuleProfileTest.java +++ b/modules/apps/vehicle-history-app/src/test/java/com/lingniu/ingest/historyapp/MavenModuleProfileTest.java @@ -93,6 +93,35 @@ class MavenModuleProfileTest { "modules/apps/xinda-push-app"); } + @Test + void optionalModuleVersionsAreScopedToTheirProfiles() throws Exception { + Document pom = rootPom(); + + assertThat(rootDependencyManagementArtifacts(pom)) + .doesNotContain( + "protocol-jt1078", + "protocol-jsatl12", + "vehicle-state-service", + "raw-archive-store", + "event-file-store", + "command-gateway", + "inbound-xinda-push", + "xinda-push-app"); + + assertThat(profileDependencyManagementArtifacts(pom, "optional-command-gateway")) + .containsExactly("protocol-jt1078", "command-gateway"); + assertThat(profileDependencyManagementArtifacts(pom, "optional-attachments")) + .containsExactly("protocol-jsatl12"); + assertThat(profileDependencyManagementArtifacts(pom, "optional-latest-state")) + .containsExactly("vehicle-state-service"); + assertThat(profileDependencyManagementArtifacts(pom, "optional-raw-archive-store")) + .containsExactly("raw-archive-store"); + assertThat(profileDependencyManagementArtifacts(pom, "optional-event-file-store")) + .containsExactly("event-file-store"); + assertThat(profileDependencyManagementArtifacts(pom, "legacy-xinda")) + .containsExactly("inbound-xinda-push", "xinda-push-app"); + } + @Test void appsDirectoryContainsOnlyRealMavenModules() throws Exception { try (Stream apps = Files.list(repositoryRoot().resolve("modules/apps"))) { @@ -232,9 +261,29 @@ class MavenModuleProfileTest { } private static List profileModules(Document pom, String profileId) { + Element profile = profile(pom, profileId); + if (profile == null) { + return List.of(); + } + return directModules(firstDirectChild(profile, "modules")); + } + + private static List rootDependencyManagementArtifacts(Document pom) { + return dependencyManagementArtifacts(pom.getDocumentElement()); + } + + private static List profileDependencyManagementArtifacts(Document pom, String profileId) { + Element profile = profile(pom, profileId); + if (profile == null) { + return List.of(); + } + return dependencyManagementArtifacts(profile); + } + + private static Element profile(Document pom, String profileId) { Element profiles = firstDirectChild(pom.getDocumentElement(), "profiles"); if (profiles == null) { - return List.of(); + return null; } NodeList children = profiles.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { @@ -243,10 +292,10 @@ class MavenModuleProfileTest { } Element id = firstDirectChild(profile, "id"); if (id != null && profileId.equals(id.getTextContent().trim())) { - return directModules(firstDirectChild(profile, "modules")); + return profile; } } - return List.of(); + return null; } private static List directModules(Element modules) { @@ -263,6 +312,32 @@ class MavenModuleProfileTest { return List.copyOf(out); } + private static List dependencyManagementArtifacts(Element owner) { + Element dependencyManagement = firstDirectChild(owner, "dependencyManagement"); + if (dependencyManagement == null) { + return List.of(); + } + Element dependencies = firstDirectChild(dependencyManagement, "dependencies"); + if (dependencies == null) { + return List.of(); + } + List artifacts = 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 + && "com.lingniu.ingest".equals(groupId.getTextContent().trim())) { + artifacts.add(artifactId.getTextContent().trim()); + } + } + return List.copyOf(artifacts); + } + private static boolean dependencyOptional(Document pom, String groupId, String artifactId) { Element dependencies = firstDirectChild(pom.getDocumentElement(), "dependencies"); if (dependencies == null) { diff --git a/pom.xml b/pom.xml index 1d029be7..471099e9 100644 --- a/pom.xml +++ b/pom.xml @@ -46,30 +46,80 @@ modules/protocols/protocol-jt1078 modules/apps/command-gateway + + + + com.lingniu.ingest + protocol-jt1078 + ${project.version} + + + com.lingniu.ingest + command-gateway + ${project.version} + + + optional-attachments modules/protocols/protocol-jsatl12 + + + + com.lingniu.ingest + protocol-jsatl12 + ${project.version} + + + optional-latest-state modules/services/vehicle-state-service + + + + com.lingniu.ingest + vehicle-state-service + ${project.version} + + + optional-raw-archive-store modules/sinks/raw-archive-store + + + + com.lingniu.ingest + raw-archive-store + ${project.version} + + + optional-event-file-store modules/sinks/event-file-store + + + + com.lingniu.ingest + event-file-store + ${project.version} + + + legacy-xinda @@ -237,16 +287,6 @@ sink-archive ${project.version} - - com.lingniu.ingest - raw-archive-store - ${project.version} - - - com.lingniu.ingest - event-file-store - ${project.version} - com.lingniu.ingest tdengine-history-store @@ -257,11 +297,6 @@ event-history-service ${project.version} - - com.lingniu.ingest - vehicle-state-service - ${project.version} - com.lingniu.ingest vehicle-stat-service @@ -277,26 +312,11 @@ protocol-jt808 ${project.version} - - com.lingniu.ingest - protocol-jt1078 - ${project.version} - - - com.lingniu.ingest - protocol-jsatl12 - ${project.version} - com.lingniu.ingest inbound-mqtt ${project.version} - - com.lingniu.ingest - command-gateway - ${project.version} - com.lingniu.ingest gb32960-ingest-app