Skip to content

Commit 6968546

Browse files
committed
[fix] Add product version handling and Maven dependency analysis
- Introduced a new system property for product version retrieval in SystemProperties.java, allowing for dynamic resolution of version placeholders. - Updated pom.xml files to include a Maven dependency plugin for analyzing unused declared dependencies, enhancing build clarity and maintenance. - Ensured consistent handling of versioning across modules to improve overall project integrity.
1 parent efa5309 commit 6968546

4 files changed

Lines changed: 87 additions & 2 deletions

File tree

exist-core/pom.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,6 +1196,7 @@ The BaseX Team. The original license statement is also included below.]]></pream
11961196
<skip>${skipUnitTests}</skip>
11971197
<argLine>@{jacocoArgLine} --add-modules jdk.incubator.vector --enable-native-access=ALL-UNNAMED -Dfile.encoding=${project.build.sourceEncoding} -Dexist.recovery.progressbar.hide=true</argLine>
11981198
<systemPropertyVariables>
1199+
<product-version>${project.version}</product-version>
11991200
<jetty.home>${project.basedir}/../exist-jetty-config/target/classes/org/exist/jetty</jetty.home>
12001201
<exist.configurationFile>${project.build.testOutputDirectory}/conf.xml</exist.configurationFile>
12011202
<exist.jetty.standalone.webapp.dir>${project.build.testOutputDirectory}/standalone-webapp</exist.jetty.standalone.webapp.dir>
@@ -1222,6 +1223,7 @@ The BaseX Team. The original license statement is also included below.]]></pream
12221223
<configuration>
12231224
<argLine>@{jacocoArgLine} --add-modules jdk.incubator.vector --enable-native-access=ALL-UNNAMED -Dfile.encoding=${project.build.sourceEncoding} -Dexist.recovery.progressbar.hide=true</argLine>
12241225
<systemPropertyVariables>
1226+
<product-version>${project.version}</product-version>
12251227
<jetty.home>${project.basedir}/../exist-jetty-config/target/classes/org/exist/jetty</jetty.home>
12261228
<exist.configurationFile>${project.build.testOutputDirectory}/conf.xml</exist.configurationFile>
12271229
<exist.jetty.standalone.webapp.dir>${project.build.testOutputDirectory}/standalone-webapp</exist.jetty.standalone.webapp.dir>

exist-core/src/main/java/org/exist/SystemProperties.java

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,35 @@ private Properties load() {
6060
}
6161

6262
public String getSystemProperty(final String propertyName) {
63-
return properties.get().getProperty(propertyName);
63+
final String value = System.getProperty(propertyName, properties.get().getProperty(propertyName));
64+
return resolveProductVersionIfPlaceholder(propertyName, value);
6465
}
6566

6667
public String getSystemProperty(final String propertyName, final String defaultValue) {
67-
return properties.get().getProperty(propertyName, defaultValue);
68+
final String value = System.getProperty(propertyName, properties.get().getProperty(propertyName, defaultValue));
69+
final String resolved = resolveProductVersionIfPlaceholder(propertyName, value);
70+
return resolved == null ? defaultValue : resolved;
71+
}
72+
73+
private String resolveProductVersionIfPlaceholder(final String propertyName, final String value) {
74+
if (!"product-version".equals(propertyName) || value == null || !isPlaceholder(value)) {
75+
return value;
76+
}
77+
78+
// In packaged runs, fall back to the implementation version from MANIFEST.MF
79+
// when CI-friendly placeholders leak through filtered resources.
80+
final Package pkg = SystemProperties.class.getPackage();
81+
if (pkg != null) {
82+
final String implementationVersion = pkg.getImplementationVersion();
83+
if (implementationVersion != null && !implementationVersion.isBlank()) {
84+
return implementationVersion;
85+
}
86+
}
87+
88+
return value;
89+
}
90+
91+
private boolean isPlaceholder(final String value) {
92+
return value.startsWith("${") && value.endsWith("}");
6893
}
6994
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* eXist-db Open Source Native XML Database
3+
* Copyright (C) 2001 The eXist-db Authors
4+
*
5+
* info@exist-db.org
6+
* http://www.exist-db.org
7+
*
8+
* This library is free software; you can redistribute it and/or
9+
* modify it under the terms of the GNU Lesser General Public
10+
* License as published by the Free Software Foundation; either
11+
* version 2.1 of the License, or (at your option) any later version.
12+
*
13+
* This library is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16+
* Lesser General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU Lesser General Public
19+
* License along with this library; if not, write to the Free Software
20+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21+
*/
22+
package org.exist;
23+
24+
import org.junit.Test;
25+
26+
import static org.junit.Assert.assertFalse;
27+
import static org.junit.Assert.assertNotNull;
28+
29+
public class VersionTest {
30+
31+
@Test
32+
public void productVersionShouldNotRemainAsPlaceholder() {
33+
final String version = Version.getVersion();
34+
assertNotNull(version);
35+
assertFalse("Version must not be an unresolved placeholder: " + version,
36+
version.startsWith("${") && version.endsWith("}"));
37+
}
38+
}

exist-service/pom.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,26 @@
9494
</execution>
9595
</executions>
9696
</plugin>
97+
98+
<plugin>
99+
<groupId>org.apache.maven.plugins</groupId>
100+
<artifactId>maven-dependency-plugin</artifactId>
101+
<executions>
102+
<execution>
103+
<id>analyze</id>
104+
<goals>
105+
<goal>analyze-only</goal>
106+
</goals>
107+
<configuration>
108+
<failOnWarning>true</failOnWarning>
109+
<!-- Used by org.exist.service.ExistDbDaemon (org.exist.start.*). -->
110+
<ignoredUnusedDeclaredDependencies>
111+
<ignoredUnusedDeclaredDependency>${project.groupId}:exist-start:jar:${project.version}</ignoredUnusedDeclaredDependency>
112+
</ignoredUnusedDeclaredDependencies>
113+
</configuration>
114+
</execution>
115+
</executions>
116+
</plugin>
97117
</plugins>
98118
</build>
99119

0 commit comments

Comments
 (0)