File tree Expand file tree Collapse file tree
main/java/io/weaviate/client6/v1/internal
test/java/io/weaviate/client6/v1/internal Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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 >
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 >
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments