Skip to content

Commit ab34440

Browse files
committed
Build: Inject git version in Javadocs and improve reproducibility
This patch updates the Ant build process to include Git versioning information in the generated Javadocs and ensures the build remains robust in environments without Git. Changes include: - Implemented a new `exec-with-default` macro in `mirth-build.xml`. This safely attempts to retrieve the Git hash and version name but falls back to default values ("unknown") if the `.git` directory is missing (e.g., source tarballs) or Git is not installed. - Updated the Javadoc target to inject a footer containing the build version. - Added conditional logic to render a hyperlink to the GitHub commit only if the revision is available; otherwise, it renders plain text. - Added the `-notimestamp` flag to the Javadoc task to support reproducible builds (ensuring identical output for identical input). - Refactored argument passing (switched from `line` to `value`) and added proper Ant namespaces for conditional execution. Signed-off-by: Tony Germano <tony@germano.name>
1 parent cae3da4 commit ab34440

2 files changed

Lines changed: 77 additions & 7 deletions

File tree

server/build.xml

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0"?>
2-
<project name="mirth-server" basedir="." default="help">
2+
<project name="mirth-server" basedir="." default="help" xmlns:if="ant:if" xmlns:unless="ant:unless">
33

44
<property name="keystore_property_file" value="keystore.properties" />
55
<property name="manifest_thread_count" value="4" />
@@ -1200,12 +1200,29 @@
12001200

12011201
<target name="create-javadocs" depends="init">
12021202
<mkdir dir="${docs.javadocs}" />
1203+
1204+
<local name="commit.rev.available" />
1205+
1206+
<condition property="commit.rev.available">
1207+
<and>
1208+
<isset property="git.commit.name" />
1209+
<not><equals arg1="${git.commit.name}" arg2="unavailable" /></not>
1210+
</and>
1211+
</condition>
12031212

12041213
<javadoc sourcepath="${src}:${jdk_src_path}" destdir="${docs.javadocs.userapi}" packagenames="com.mirth.connect.server.userutil,com.mirth.connect.userutil,com.mirth.connect.plugins.httpauth.userutil" link="https://docs.oracle.com/en/java/javase/17/docs/api/">
12051214
<classpath refid="classpath" />
1206-
<arg line="-html5"/>
1207-
<arg line="--add-modules=java.sql.rowset"/>
1208-
<arg line="--add-exports=java.sql.rowset/com.sun.rowset=ALL-UNNAMED"/>
1215+
<bottom if:true="${commit.rev.available}">
1216+
<![CDATA[Built from Git revision: <a href="https://github.com/OpenIntegrationEngine/engine/commit/${git.commit.hash}">${git.commit.name}</a><br>]]>
1217+
<![CDATA[Licensed under the <a href="https://www.mozilla.org/MPL/2.0/">Mozilla Public License 2.0</a>.]]>
1218+
</bottom>
1219+
<bottom unless:true="${commit.rev.available}">
1220+
<![CDATA[Built from Git revision: unknown<br>]]>
1221+
<![CDATA[Licensed under the <a href="https://www.mozilla.org/MPL/2.0/">Mozilla Public License 2.0</a>.]]>
1222+
</bottom>
1223+
<arg value="-notimestamp"/>
1224+
<arg value="--add-modules=java.sql.rowset"/>
1225+
<arg value="--add-exports=java.sql.rowset/com.sun.rowset=ALL-UNNAMED"/>
12091226
</javadoc>
12101227
</target>
12111228

server/mirth-build.xml

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,67 @@
11
<project name="mirth-connect" basedir="." default="build">
2+
<macrodef name="exec-with-default">
3+
<attribute name="executable" />
4+
<attribute name="property" />
5+
<attribute name="default" />
6+
<element name="args" optional="true" />
7+
<sequential>
8+
<!-- Use <local> so these names can be reused in multiple calls -->
9+
<local name="temp.output" />
10+
<local name="temp.status" />
11+
12+
<!-- 1. Run the command -->
13+
<exec executable="@{executable}"
14+
outputproperty="temp.output"
15+
resultproperty="temp.status"
16+
failonerror="false">
17+
<args />
18+
</exec>
19+
20+
<!-- 2. Assign the real property ONLY if successful (exit code 0) -->
21+
<condition property="@{property}" value="${temp.output}">
22+
<equals arg1="${temp.status}" arg2="0" />
23+
</condition>
24+
25+
<!-- 3. Fallback to default if @{property} is still unset -->
26+
<property name="@{property}" value="@{default}" />
27+
</sequential>
28+
</macrodef>
29+
230
<target name="init">
331
<property file="mirth-build.properties" />
432
<property name="donkey.setup" value="${donkey}/setup" />
533
<property name="server.setup" value="${server}/setup" />
634
<property name="server.build" value="${server}/build" />
735

36+
<!--
37+
The following tasks use exec-with-default macro defined above.
38+
Default values are used in case the source code is being compiled where git is not available.
39+
-->
40+
841
<!-- Get the timestamp of the current git commit in ISO-8601 format-->
9-
<exec executable="git" outputproperty="git.commit.timestamp" failonerror="false">
10-
<arg line="log -1 --pretty=%cI"/>
11-
</exec>
42+
<exec-with-default executable="git" property="git.commit.timestamp" default="2025-03-25T22:28:08.664Z">
43+
<args><arg line="log -1 --pretty=%cI"/></args>
44+
</exec-with-default>
45+
<echo>Using git.commit.timestamp of [${git.commit.timestamp}]</echo>
46+
47+
<!-- Get the long hash of the current git commit -->
48+
<exec-with-default executable="git" property="git.commit.hash" default="">
49+
<args><arg line="rev-parse HEAD"/></args>
50+
</exec-with-default>
51+
<echo>Using git.commit.hash of [${git.commit.hash}]</echo>
52+
53+
<!-- Get the human readable name of the current git commit for build version -->
54+
<exec-with-default executable="git" property="git.commit.name" default="unavailable">
55+
<args>
56+
<arg value="describe" />
57+
<arg value="--match" />
58+
<arg value="v[0-9]*" />
59+
<arg value="--tags" />
60+
<arg value="--long" />
61+
<arg value="--dirty" />
62+
</args>
63+
</exec-with-default>
64+
<echo>Using git.commit.name of [${git.commit.name}]</echo>
1265
</target>
1366

1467
<!-- Donkey -->

0 commit comments

Comments
 (0)