MCPcopy Create free account
hub / github.com/apache/jena / ModVersion

Class ModVersion

jena-cmds/src/main/java/org/apache/jena/cmd/ModVersion.java:39–93  ·  view source on GitHub ↗

Version information. The version is the manifest entry in the jar file for a class. It is not available if the class comes from a development tree where the class file is from "target" (maven).

Source from the content-addressed store, hash-verified

37 * class file is from "target" (maven).
38 */
39public class ModVersion extends ModBase
40{
41 protected final ArgDecl versionDecl = new ArgDecl(ArgDecl.NoValue, "version");
42 protected boolean version = false;
43 protected boolean printAndExit = false;
44
45 // (system name, version string)
46 private List<Pair<String, Optional<String>>> descriptions = new ArrayList<>();
47
48 public ModVersion(boolean printAndExit) {
49 this.printAndExit = printAndExit;
50 }
51
52 /** Add a class for the version number */
53 public void addClass(Class<? > c) {
54 addClass(c.getSimpleName(), c);
55 }
56
57 /** Add a label and a class for the version number */
58 public void addClass(String name, Class<? > cls) {
59 Pair<String, Optional<String>> desc = Pair.create(name, Version.versionForClass(cls));
60 descriptions.add(desc);
61 }
62
63 @Override
64 public void registerWith(CmdGeneral cmdLine) {
65 cmdLine.add(versionDecl, "--version", "Version information");
66 }
67
68 @Override
69 public void processArgs(CmdArgModule cmdLine) {
70 if ( cmdLine.contains(versionDecl) )
71 version = true;
72 // The --version flag causes us to print and exit.
73 if ( version && printAndExit )
74 printVersionAndExit();
75 }
76
77 public boolean getVersionFlag() {
78 return version;
79 }
80
81 public void printVersion() {
82 if ( descriptions.isEmpty() ) {
83 Version.printVersion(System.out, null, Version.versionForClass(Jena.class));
84 return;
85 }
86 descriptions.forEach(p->Version.printVersion(System.out, p.getLeft(), p.getRight()));
87 }
88
89 public void printVersionAndExit() {
90 printVersion();
91 System.exit(0);
92 }
93}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected