Skip to content

Commit db7d6fb

Browse files
committed
Include git commit ID in manifest
1 parent 192d97c commit db7d6fb

File tree

8 files changed

+30
-1
lines changed

8 files changed

+30
-1
lines changed

build.gradle

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,15 @@ task assembleJavadoc(type: Sync) {
7474
destinationDir = file("${rootProject.buildDir}/javadoc")
7575
}
7676

77+
String getGitCommit() {
78+
def proc = "git rev-parse HEAD".execute(null, projectDir)
79+
proc.waitFor()
80+
if (proc.exitValue() != 0) {
81+
throw new RuntimeException("Failed to get git commit ID");
82+
}
83+
return proc.text.trim()
84+
}
85+
7786
subprojects { project ->
7887

7988
sourceCompatibility = 1.8

test-dependent-projects/java-dep-webauthn-server-attestation/src/test/java/com/yubico/webauthn/attestation/ManifestInfoTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,9 @@ public void standardImplementationPropertiesAreSet() throws IOException {
3232
assertEquals("Yubico", lookup("Implementation-Vendor"));
3333
}
3434

35+
@Test
36+
public void customImplementationPropertiesAreSet() throws IOException {
37+
assertTrue(lookup("Git-Commit").matches("^[a-f0-9]{40}$"));
38+
}
39+
3540
}

test-dependent-projects/java-dep-webauthn-server-core/src/test/java/com/yubico/webauthn/meta/ManifestInfoTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,9 @@ public void standardImplementationPropertiesAreSet() throws IOException {
5050
assertEquals("Yubico", lookup("Implementation-Vendor"));
5151
}
5252

53+
@Test
54+
public void customImplementationPropertiesAreSet() throws IOException {
55+
assertTrue(lookup("Git-Commit").matches("^[a-f0-9]{40}$"));
56+
}
57+
5358
}

test-dependent-projects/java-dep-webauthn-server-core/src/test/java/com/yubico/webauthn/meta/VersionInfoTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public void implementationPropertiesAreSet() {
2828
final Implementation impl = versionInfo.getImplementation();
2929
assertTrue(impl.getSourceCodeUrl().toExternalForm().startsWith("https://"));
3030
assertTrue(impl.getVersion().matches("^\\d+\\.\\d+\\.\\d+(-.*)?"));
31+
assertTrue(impl.getGitCommit().matches("^[a-f0-9]{40}$"));
3132
}
3233

3334
@Test

webauthn-server-attestation/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ jar {
4646
'Implementation-Title': project.description,
4747
'Implementation-Version': project.version,
4848
'Implementation-Vendor': 'Yubico',
49+
'Git-Commit': getGitCommit(),
4950
])
5051
}
5152
}

webauthn-server-core/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ jar {
5555
'Implementation-Version': project.version,
5656
'Implementation-Vendor': 'Yubico',
5757
'Implementation-Source-Url': 'https://github.com/Yubico/java-webauthn-server',
58+
'Git-Commit': getGitCommit(),
5859
])
5960
}
6061
}

webauthn-server-core/src/main/java/com/yubico/webauthn/meta/Implementation.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,10 @@ public class Implementation {
5151
@NonNull
5252
private final URL sourceCodeUrl;
5353

54+
/**
55+
* The commit ID of the source code the library was built from, if known.
56+
*/
57+
@NonNull
58+
private final String gitCommit;
59+
5460
}

webauthn-server-core/src/main/java/com/yubico/webauthn/meta/VersionInfo.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ public static VersionInfo getInstance() {
7474
*/
7575
private final Implementation implementation = new Implementation(
7676
findValueInManifest("Implementation-Version"),
77-
new URL(findValueInManifest("Implementation-Source-Url"))
77+
new URL(findValueInManifest("Implementation-Source-Url")),
78+
findValueInManifest("Git-Commit")
7879
);
7980

8081
private VersionInfo() throws IOException {

0 commit comments

Comments
 (0)