mirror of
https://github.com/imgfloat/server.git
synced 2026-02-05 11:49:25 +00:00
Remove git versioning
This commit is contained in:
@@ -4,9 +4,7 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class VersionService {
|
public class VersionService {
|
||||||
@@ -28,21 +26,11 @@ public class VersionService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String resolveVersion() {
|
private String resolveVersion() {
|
||||||
String manifestVersion = getClass().getPackage().getImplementationVersion();
|
|
||||||
if (manifestVersion != null && !manifestVersion.isBlank()) {
|
|
||||||
return manifestVersion;
|
|
||||||
}
|
|
||||||
|
|
||||||
String pomVersion = getPomVersion();
|
String pomVersion = getPomVersion();
|
||||||
if (pomVersion != null && !pomVersion.isBlank()) {
|
if (pomVersion != null && !pomVersion.isBlank()) {
|
||||||
return pomVersion;
|
return pomVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
String gitDescribeVersion = getGitVersionString();
|
|
||||||
if (gitDescribeVersion != null) {
|
|
||||||
return "git-" + gitDescribeVersion;
|
|
||||||
}
|
|
||||||
|
|
||||||
return "unknown";
|
return "unknown";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,7 +40,6 @@ public class VersionService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String normalized = baseVersion.trim();
|
String normalized = baseVersion.trim();
|
||||||
normalized = normalized.replaceFirst("^git-", "");
|
|
||||||
normalized = normalized.replaceFirst("(?i)^v", "");
|
normalized = normalized.replaceFirst("(?i)^v", "");
|
||||||
normalized = normalized.replaceFirst("-SNAPSHOT$", "");
|
normalized = normalized.replaceFirst("-SNAPSHOT$", "");
|
||||||
if (normalized.isBlank()) {
|
if (normalized.isBlank()) {
|
||||||
@@ -77,47 +64,4 @@ public class VersionService {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getGitVersionString() {
|
|
||||||
try {
|
|
||||||
Process check = new ProcessBuilder("git", "--version")
|
|
||||||
.redirectErrorStream(true)
|
|
||||||
.start();
|
|
||||||
|
|
||||||
if (check.waitFor() != 0) {
|
|
||||||
LOG.info("git not found on PATH, skipping git version detection");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
LOG.info("git not found on PATH, skipping git version detection");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
Process process = null;
|
|
||||||
try {
|
|
||||||
process = new ProcessBuilder("git", "describe", "--tags", "--always")
|
|
||||||
.redirectErrorStream(true)
|
|
||||||
.start();
|
|
||||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
|
|
||||||
String result = reader.readLine();
|
|
||||||
int exitCode = process.waitFor();
|
|
||||||
if (exitCode == 0 && result != null && !result.isBlank()) {
|
|
||||||
return result.trim();
|
|
||||||
}
|
|
||||||
LOG.warn("git describe returned exit code {} with output: {}", exitCode, result);
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
LOG.warn("Unable to determine git version using git describe", e);
|
|
||||||
if (process != null) {
|
|
||||||
process.destroyForcibly();
|
|
||||||
}
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
LOG.warn("Interrupted while determining git version", e);
|
|
||||||
if (process != null) {
|
|
||||||
process.destroyForcibly();
|
|
||||||
}
|
|
||||||
Thread.currentThread().interrupt();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user