Skip to content

Commit b11fb22

Browse files
author
minh
committed
feat: More details when call gis --version
fix: #90
1 parent cb6277d commit b11fb22

File tree

9 files changed

+77
-106
lines changed

9 files changed

+77
-106
lines changed

.dockerignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
.git
21
.gitignore
32
.vscode
43
target

Containerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ USER root
1313
WORKDIR /app/gis
1414
COPY --from=build /app/gis/target/gis-*.jar target/
1515
COPY --from=build /app/gis/target/lib target/lib
16-
RUN native-image -march=compatibility -cp target/gis-*.jar "org.nqm.Gis" --no-fallback
16+
RUN native-image -march=compatibility -cp target/gis-*.jar "org.nqm.Gis" --no-fallback -H:IncludeResources=".properties"
1717
RUN mv org.nqm.gis gis
1818
RUN chmod +x gis
1919
RUN ./gis --version

integration_test.sh

-99
This file was deleted.

pom.xml

+31-4
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
<groupId>org.nqm</groupId>
66
<artifactId>gis</artifactId>
77
<version>2.0.0-dev</version>
8-
<packaging>${packaging}</packaging>
8+
<packaging>jar</packaging>
99

1010
<properties>
11+
<commit.hash>${git.commit.id.abbrev}</commit.hash>
1112
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1213
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
13-
<packaging>jar</packaging>
1414
<maven.compiler.target>21</maven.compiler.target>
1515
<maven.compiler.source>21</maven.compiler.source>
1616
<picocli.version>4.7.6</picocli.version>
@@ -22,6 +22,8 @@
2222
<maven-surefire.version>3.3.0</maven-surefire.version>
2323
<compiler.plugin.version>3.12.1</compiler.plugin.version>
2424
<jar.plugin.version>3.3.0</jar.plugin.version>
25+
<jacoco.version>0.8.12</jacoco.version>
26+
<commit.id.version>9.0.1</commit.id.version>
2527
</properties>
2628

2729
<dependencies>
@@ -78,6 +80,12 @@
7880

7981
<build>
8082
<defaultGoal>package</defaultGoal>
83+
<resources>
84+
<resource>
85+
<directory>src/main/resources</directory>
86+
<filtering>true</filtering>
87+
</resource>
88+
</resources>
8189
<plugins>
8290
<plugin>
8391
<groupId>org.apache.maven.plugins</groupId>
@@ -153,10 +161,10 @@
153161
<plugin>
154162
<groupId>org.jacoco</groupId>
155163
<artifactId>jacoco-maven-plugin</artifactId>
156-
<version>0.8.12</version>
164+
<version>${jacoco.version}</version>
157165
<executions>
158166
<execution>
159-
<id>prepare-agent</id>
167+
<phase>test-compile</phase>
160168
<goals>
161169
<goal>prepare-agent</goal>
162170
</goals>
@@ -174,6 +182,25 @@
174182
</execution>
175183
</executions>
176184
</plugin>
185+
<plugin>
186+
<groupId>io.github.git-commit-id</groupId>
187+
<artifactId>git-commit-id-maven-plugin</artifactId>
188+
<version>${commit.id.version}</version>
189+
<executions>
190+
<execution>
191+
<id>get-the-git-infos</id>
192+
<goals>
193+
<goal>revision</goal>
194+
</goals>
195+
<phase>process-sources</phase>
196+
</execution>
197+
</executions>
198+
<configuration>
199+
<includeOnlyProperties>
200+
<includeOnlyProperty>^git.commit.id.abbrev$</includeOnlyProperty>
201+
</includeOnlyProperties>
202+
</configuration>
203+
</plugin>
177204
</plugins>
178205
</build>
179206
</project>

src/main/java/org/nqm/Gis.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.nqm;
22

3+
import org.nqm.command.GisVersion;
34
import org.nqm.command.GitCommand;
45
import org.nqm.config.GisLog;
56
import org.nqm.exception.GisException;
@@ -14,7 +15,7 @@
1415
name = "gis",
1516
description = "Git extension wrapper which supports submodules",
1617
mixinStandardHelpOptions = true,
17-
version = "2.0.0-dev")
18+
versionProvider = GisVersion.class)
1819
public class Gis extends GitCommand {
1920

2021
private static final IExecutionExceptionHandler GLOBAL_EXCEPTION_HANLER = new IExecutionExceptionHandler() {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package org.nqm.command;
2+
3+
import java.util.Properties;
4+
import picocli.CommandLine.IVersionProvider;
5+
6+
public class GisVersion implements IVersionProvider {
7+
8+
@Override
9+
public String[] getVersion() throws Exception {
10+
var p = new Properties();
11+
var gisVersion = "";
12+
var commitHash = "";
13+
try (var gisConfigs = this.getClass().getClassLoader().getResourceAsStream(".properties")) {
14+
p.load(gisConfigs);
15+
gisVersion = p.getProperty("gis.version");
16+
commitHash = p.getProperty("git.commit.hash");
17+
}
18+
return new String[] {"gis " + gisVersion, "commit " + commitHash};
19+
}
20+
}

src/main/resources/.properties

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
gis.version=${project.version}
2+
git.commit.hash=${commit.hash}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package org.nqm.command;
2+
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
import org.junit.jupiter.api.Test;
5+
6+
class GisVersionTest {
7+
8+
@Test
9+
void getVersion_OK() throws Exception {
10+
// given:
11+
var gisVersion = new GisVersion();
12+
13+
// when:
14+
var version = gisVersion.getVersion();
15+
16+
// then:
17+
assertThat(version).containsExactly("gis 1.2.3-dev", "commit 44e3d50");
18+
}
19+
}

src/test/resources/.properties

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
gis.version=1.2.3-dev
2+
git.commit.hash=44e3d50

0 commit comments

Comments
 (0)