Skip to content

Commit 3831bfe

Browse files
committed
Make Git not required to build
A Git repository will still be required to get accurate version numbers and to publish artifacts, but the project can now be built and pass the tests without a local Git repository.
1 parent 61bb444 commit 3831bfe

File tree

7 files changed

+24
-11
lines changed

7 files changed

+24
-11
lines changed

build.gradle

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,15 @@ String getGitCommit() {
121121
def proc = "git rev-parse HEAD".execute(null, projectDir)
122122
proc.waitFor()
123123
if (proc.exitValue() != 0) {
124-
throw new RuntimeException("Failed to get git commit ID");
124+
return null
125125
}
126126
return proc.text.trim()
127127
}
128128

129+
String getGitCommitOrUnknown() {
130+
return getGitCommit() ?: 'UNKNOWN'
131+
}
132+
129133
subprojects { project ->
130134

131135
if (project.plugins.hasPlugin('scala')) {
@@ -212,6 +216,10 @@ subprojects { project ->
212216
apply plugin: 'maven-publish'
213217
apply plugin: 'signing'
214218

219+
if (getGitCommit() == null) {
220+
throw new RuntimeException("Failed to get git commit ID");
221+
}
222+
215223
publishing {
216224
publications {
217225
jars(MavenPublication) {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public void standardImplementationPropertiesAreSet() throws IOException {
3636

3737
@Test
3838
public void customImplementationPropertiesAreSet() throws IOException {
39-
assertTrue(lookup("Git-Commit").matches("^[a-f0-9]{40}$"));
39+
assertTrue(
40+
lookup("Git-Commit").matches("^[a-f0-9]{40}$") || lookup("Git-Commit").equals("UNKNOWN"));
4041
}
4142
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public void standardImplementationPropertiesAreSet() throws IOException {
5454

5555
@Test
5656
public void customImplementationPropertiesAreSet() throws IOException {
57-
assertTrue(lookup("Git-Commit").matches("^[a-f0-9]{40}$"));
57+
assertTrue(
58+
lookup("Git-Commit").matches("^[a-f0-9]{40}$") || lookup("Git-Commit").equals("UNKNOWN"));
5859
}
5960
}

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,17 @@ 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}$"));
31+
assertTrue(
32+
impl.getGitCommit().matches("^[a-f0-9]{40}$") || impl.getGitCommit().equals("UNKNOWN"));
3233
}
3334

3435
@Test
35-
public void majorVersionIsAtLeast1() {
36+
public void majorVersionIsUnknownOrAtLeast1() {
3637
final String version = versionInfo.getImplementation().getVersion();
37-
String[] splits = version.split("\\.");
38-
final int majorVersion = Integer.parseInt(splits[0]);
39-
assertTrue(majorVersion >= 1);
38+
if (!"0.1.0-SNAPSHOT".equals(version)) {
39+
String[] splits = version.split("\\.");
40+
final int majorVersion = Integer.parseInt(splits[0]);
41+
assertTrue(majorVersion >= 1);
42+
}
4043
}
4144
}

webauthn-server-attestation/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ jar {
5858
'Implementation-Title': project.description,
5959
'Implementation-Version': project.version,
6060
'Implementation-Vendor': 'Yubico',
61-
'Git-Commit': getGitCommit(),
61+
'Git-Commit': getGitCommitOrUnknown(),
6262
])
6363
}
6464
}

webauthn-server-core-bundle/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jar {
2727
'Implementation-Version': project.version,
2828
'Implementation-Vendor': 'Yubico',
2929
'Implementation-Source-Url': 'https://github.com/Yubico/java-webauthn-server',
30-
'Git-Commit': getGitCommit(),
30+
'Git-Commit': getGitCommitOrUnknown(),
3131
])
3232
}
3333
}

webauthn-server-core/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ jar {
6767
'Implementation-Version': project.version,
6868
'Implementation-Vendor': 'Yubico',
6969
'Implementation-Source-Url': 'https://github.com/Yubico/java-webauthn-server',
70-
'Git-Commit': getGitCommit(),
70+
'Git-Commit': getGitCommitOrUnknown(),
7171
])
7272
}
7373
}

0 commit comments

Comments
 (0)