-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVersionCommand.java
More file actions
73 lines (62 loc) · 2.84 KB
/
Copy pathVersionCommand.java
File metadata and controls
73 lines (62 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package io.github.randomcodespace.iq.cli;
import io.github.randomcodespace.iq.detector.DetectorRegistry;
import org.springframework.boot.info.BuildProperties;
import org.springframework.stereotype.Component;
import picocli.CommandLine.Command;
import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.Callable;
/**
* Show version and environment info.
*/
@Component
@Command(name = "version", mixinStandardHelpOptions = true,
description = "Show version info")
public class VersionCommand implements Callable<Integer> {
/** Fallback version used when BuildProperties is unavailable (e.g. running from IDE). */
public static final String VERSION = resolveVersion();
private final DetectorRegistry registry;
private final BuildProperties buildProperties;
public VersionCommand(DetectorRegistry registry,
@org.springframework.lang.Nullable BuildProperties buildProperties) {
this.registry = registry;
this.buildProperties = buildProperties;
}
private static String resolveVersion() {
// Try reading from build-info.properties on the classpath (generated by spring-boot-maven-plugin)
try (var is = VersionCommand.class.getResourceAsStream("/META-INF/build-info.properties")) {
if (is != null) {
var props = new java.util.Properties();
props.load(is);
String v = props.getProperty("build.version");
if (v != null && !v.isBlank()) return v;
}
} catch (java.io.IOException ignored) {
// build-info.properties is optional; fall through to manifest lookup.
}
// Fallback: Implementation-Version from JAR manifest
String v = VersionCommand.class.getPackage().getImplementationVersion();
return v != null ? v : "dev";
}
@Override
public Integer call() {
// Prefer Spring BuildProperties (populated at runtime) over static resolution
String version = buildProperties != null
? buildProperties.getVersion()
: VERSION;
Set<String> allLanguages = new TreeSet<>();
for (var d : registry.allDetectors()) {
allLanguages.addAll(d.getSupportedLanguages());
}
CliOutput.bold("Code IQ " + version);
CliOutput.info(" Java: " + System.getProperty("java.version")
+ " (" + System.getProperty("java.vendor") + ")");
CliOutput.info(" Runtime: " + System.getProperty("java.runtime.name"));
CliOutput.info(" OS: " + System.getProperty("os.name")
+ " " + System.getProperty("os.arch"));
CliOutput.info(" Detectors: " + registry.count());
CliOutput.info(" Languages: " + allLanguages.size());
CliOutput.info(" Backend: Neo4j Embedded");
return 0;
}
}