1+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2+ <!-- Maven POM for generating Git-based version properties for Greengrass Nucleus -->
3+ <project xmlns =" http://maven.apache.org/POM/4.0.0"
4+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
5+ xsi : schemaLocation =" http://maven.apache.org/POM/4.0.0
6+ http://maven.apache.org/xsd/maven-4.0.0.xsd" >
7+ <modelVersion >4.0.0</modelVersion >
8+ <groupId >com.aws.greengrass</groupId >
9+ <artifactId >nucleus-build-version</artifactId >
10+ <version >1.0.0</version >
11+ <packaging >pom</packaging >
12+
13+ <build >
14+ <plugins >
15+ <!-- Extract Git information and write to properties file -->
16+ <plugin >
17+ <groupId >org.apache.maven.plugins</groupId >
18+ <artifactId >maven-antrun-plugin</artifactId >
19+ <version >3.1.0</version >
20+ <executions >
21+ <!-- Get current Git branch name -->
22+ <execution >
23+ <id >set-git-branch-info</id >
24+ <phase >initialize</phase >
25+ <goals >
26+ <goal >run</goal >
27+ </goals >
28+ <configuration >
29+ <target >
30+ <!-- Execute git command to get current branch -->
31+ <exec executable =" git" outputproperty =" git.branch" >
32+ <arg value =" branch" />
33+ <arg value =" --show-current" />
34+ </exec >
35+ <!-- Write branch name to git.properties file -->
36+ <echo file =" ${project.build.directory}/git.properties" append =" true" >git.branch=${git.branch}${line.separator}</echo >
37+ </target >
38+ </configuration >
39+ </execution >
40+ <!-- Get latest Git tag for version determination -->
41+ <execution >
42+ <id >set-git-latest-tag-info</id >
43+ <phase >initialize</phase >
44+ <goals >
45+ <goal >run</goal >
46+ </goals >
47+ <configuration >
48+ <target >
49+ <!-- Get the most recent tag sorted by version -->
50+ <exec executable =" git" outputproperty =" git.latest.tag" >
51+ <arg value =" for-each-ref" />
52+ <arg value =" --count=1" />
53+ <arg value =" --sort=-version:refname" />
54+ <arg value =" --format=%(refname:short)" />
55+ <arg value =" refs/tags" />
56+ </exec >
57+ <!-- Write latest tag to git.properties file -->
58+ <echo file =" ${project.build.directory}/git.properties" append =" true" >git.latest.tag=${git.latest.tag}${line.separator}</echo >
59+ </target >
60+ </configuration >
61+ </execution >
62+ </executions >
63+ </plugin >
64+
65+ <!-- Load the generated Git properties into Maven properties -->
66+ <plugin >
67+ <groupId >org.codehaus.mojo</groupId >
68+ <artifactId >properties-maven-plugin</artifactId >
69+ <version >1.1.0</version >
70+ <executions >
71+ <execution >
72+ <phase >initialize</phase >
73+ <goals >
74+ <goal >read-project-properties</goal >
75+ </goals >
76+ <configuration >
77+ <files >
78+ <!-- Read the git.properties file created above -->
79+ <file >${project.build.directory}/git.properties</file >
80+ </files >
81+ </configuration >
82+ </execution >
83+ </executions >
84+ </plugin >
85+
86+ <!-- Process version strings using regex transformations -->
87+ <plugin >
88+ <groupId >org.codehaus.mojo</groupId >
89+ <artifactId >build-helper-maven-plugin</artifactId >
90+ <version >3.6.1</version >
91+ <executions >
92+ <!-- Check if current branch is a release branch -->
93+ <execution >
94+ <id >process-release-branch-info</id >
95+ <phase >initialize</phase >
96+ <goals ><goal >regex-property</goal ></goals >
97+ <configuration >
98+ <name >release.branch.match</name >
99+ <value >${git.branch}</value >
100+ <!-- Match release_MAJOR.MINOR.x pattern and extract version -->
101+ <regex >^release_(\d+\.\d+)\.x$</regex >
102+ <!-- Transform release_MAJOR.MINOR.x to MAJOR.MINOR.0 -->
103+ <replacement >$1.0</replacement >
104+ <failIfNoMatch >false</failIfNoMatch >
105+ </configuration >
106+ </execution >
107+ <!-- Set final branch version (dev for non-release branches) -->
108+ <execution >
109+ <id >process-non-release-branch-info</id >
110+ <phase >initialize</phase >
111+ <goals ><goal >regex-property</goal ></goals >
112+ <configuration >
113+ <name >git.current.branch.snapshot</name >
114+ <value >${release.branch.match}</value >
115+ <!-- Default to 'dev' if not a release branch -->
116+ <regex >^${git.branch}$</regex >
117+ <replacement >dev</replacement >
118+ <failIfNoMatch >false</failIfNoMatch >
119+ </configuration >
120+ </execution >
121+ <!-- Convert latest tag to SNAPSHOT version format -->
122+ <execution >
123+ <id >process-latest-tag-info</id >
124+ <phase >initialize</phase >
125+ <goals ><goal >regex-property</goal ></goals >
126+ <configuration >
127+ <name >git.latest.tag.snapshot</name >
128+ <value >${git.latest.tag}</value >
129+ <!-- Transform vMAJOR.MINOR.PATCH to MAJOR.MINOR.0-SNAPSHOT -->
130+ <regex >^v?(\d+)\.(\d+)\.\d+.*$</regex >
131+ <replacement >$1.$2.0-SNAPSHOT</replacement >
132+ <failIfNoMatch >false</failIfNoMatch >
133+ </configuration >
134+ </execution >
135+ </executions >
136+ </plugin >
137+
138+ <!-- Write final git.current.branch.snapshot version information -->
139+ <plugin >
140+ <groupId >org.apache.maven.plugins</groupId >
141+ <artifactId >maven-antrun-plugin</artifactId >
142+ <version >3.1.0</version >
143+ <executions >
144+ <execution >
145+ <id >set-build-snapshot-version</id >
146+ <phase >compile</phase >
147+ <goals ><goal >run</goal ></goals >
148+ <configuration >
149+ <target >
150+ <!-- Append final branch snapshot version to properties -->
151+ <echo file =" ${project.build.directory}/git.properties" append =" true" >git.current.branch.snapshot=${git.current.branch.snapshot}${line.separator}</echo >
152+ </target >
153+ </configuration >
154+ </execution >
155+ </executions >
156+ </plugin >
157+ </plugins >
158+ </build >
159+ </project >
0 commit comments