Skip to content

Commit ebca3a8

Browse files
committed
feat: include client6 build info in the resources
Replaced git-commit-id-maven-plugin with an better-maintained mirror. The original packaged lacked native Git support, which would impede the plugin if git-worktrees were used.
1 parent fd25bb7 commit ebca3a8

3 files changed

Lines changed: 89 additions & 0 deletions

File tree

pom.xml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,28 @@
360360
</execution>
361361
</executions>
362362
</plugin>
363+
<plugin>
364+
<groupId>pl.project13.maven</groupId>
365+
<artifactId>git-commit-id-plugin</artifactId>
366+
<version>4.9.10</version>
367+
<executions>
368+
<execution>
369+
<id>get-the-git-infos</id>
370+
<goals>
371+
<goal>revision</goal>
372+
</goals>
373+
<phase>initialize</phase>
374+
</execution>
375+
</executions>
376+
<configuration>
377+
<useNativeGit>true</useNativeGit>
378+
<generateGitPropertiesFile>true</generateGitPropertiesFile>
379+
<generateGitPropertiesFilename>${project.build.outputDirectory}/client6-git.properties</generateGitPropertiesFilename>
380+
<commitIdGenerationMode>full</commitIdGenerationMode>
381+
<failOnNoGitDirectory>false</failOnNoGitDirectory>
382+
<failOnUnableToExtractRepoInfo>false</failOnUnableToExtractRepoInfo>
383+
</configuration>
384+
</plugin>
363385
<plugin>
364386
<groupId>org.apache.maven.plugins</groupId>
365387
<artifactId>maven-javadoc-plugin</artifactId>
@@ -522,6 +544,10 @@
522544
<groupId>org.apache.maven.plugins</groupId>
523545
<artifactId>maven-javadoc-plugin</artifactId>
524546
</plugin>
547+
<plugin>
548+
<groupId>pl.project13.maven</groupId>
549+
<artifactId>git-commit-id-plugin</artifactId>
550+
</plugin>
525551
<plugin>
526552
<groupId>org.apache.maven.plugins</groupId>
527553
<artifactId>maven-gpg-plugin</artifactId>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package io.weaviate.client6.v1.internal;
2+
3+
import java.io.IOException;
4+
import java.util.Properties;
5+
6+
public final class BuildInfo {
7+
/** Prevent public initialization. */
8+
private BuildInfo() {
9+
}
10+
11+
public static final String BRANCH;
12+
public static final String COMMIT_ID;
13+
public static final String COMMIT_ID_ABBREV;
14+
15+
static {
16+
var properties = new Properties();
17+
18+
try {
19+
properties.load(BuildInfo.class.getClassLoader().getResourceAsStream("client6-git.properties"));
20+
} catch (IOException | NullPointerException e) {
21+
System.out.println("failed to load client6-git.properties, no build information will be available");
22+
}
23+
24+
BRANCH = String.valueOf(properties.get("git.branch"));
25+
COMMIT_ID = String.valueOf(properties.get("git.commit.id.full"));
26+
COMMIT_ID_ABBREV = String.valueOf(properties.get("git.commit.id.abbrev"));
27+
}
28+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package io.weaviate.client6.v1.internal;
2+
3+
import java.io.BufferedReader;
4+
import java.io.IOException;
5+
import java.io.InputStreamReader;
6+
7+
import org.assertj.core.api.Assertions;
8+
import org.junit.Test;
9+
10+
public class BuildInfoTest {
11+
12+
@Test
13+
public void testBuildInfo() throws IOException {
14+
Assertions.assertThat(BuildInfo.BRANCH).as("branch").isEqualTo(gitBranch());
15+
Assertions.assertThat(BuildInfo.COMMIT_ID).as("commit.full").isEqualTo(gitCommit());
16+
Assertions.assertThat(gitCommit()).as("commit.abbrev").startsWith(BuildInfo.COMMIT_ID_ABBREV);
17+
}
18+
19+
/** Get current non-abbreviated Git commit hash. */
20+
private static String gitCommit() throws IOException {
21+
return runCommand("git", "rev-parse", "HEAD");
22+
}
23+
24+
/** Get current git branch. */
25+
private static String gitBranch() throws IOException {
26+
return runCommand("git", "branch", "--show-current");
27+
}
28+
29+
/** Run shell command and return the output as multi-line string. */
30+
private static String runCommand(String... cmdarray) throws IOException {
31+
var process = Runtime.getRuntime().exec(cmdarray);
32+
var r = new BufferedReader(new InputStreamReader(process.getInputStream()));
33+
return String.join("\n", (Iterable<String>) () -> r.lines().iterator());
34+
}
35+
}

0 commit comments

Comments
 (0)