Skip to content
Snippets Groups Projects
Commit 091ba271 authored by dgelessus's avatar dgelessus
Browse files

Improve :version command

Now also displays the version of the ProB 2 Jupyter kernel and more
detailed info about the ProB CLI version.
parent 2b75217b
Branches
Tags
No related merge requests found
...@@ -52,6 +52,21 @@ tasks.withType(JavaCompile) { ...@@ -52,6 +52,21 @@ tasks.withType(JavaCompile) {
options.encoding = SOURCE_ENCODING options.encoding = SOURCE_ENCODING
} }
def readCurrentGitCommit() {
def proc = ["git", "rev-parse", "HEAD"].execute(null, project.projectDir)
def exitCode = proc.waitFor()
if (exitCode != 0) {
throw new IllegalStateException("git rev-parse command exited with status code ${exitCode}:\n" + proc.err.readLines().join("\n"))
}
return proc.in.readLines()[0]
}
processResources {
filesMatching("de/prob2/jupyter/build.properties") {
expand(version: project.version, commit: readCurrentGitCommit())
}
}
mainClassName = "de.prob2.jupyter.Main" mainClassName = "de.prob2.jupyter.Main"
final KERNEL_SPEC_FILES_PATH = sourceSets.main.resources.sourceDirectories.singleFile.toPath().resolve(Paths.get("de", "prob2", "jupyter", "kernelspecfiles")) final KERNEL_SPEC_FILES_PATH = sourceSets.main.resources.sourceDirectories.singleFile.toPath().resolve(Paths.get("de", "prob2", "jupyter", "kernelspecfiles"))
......
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` prob ``` prob
:help :version :help :version
``` ```
%% Output %% Output
``` ```
:version :version
``` ```
Display version info about the ProB CLI and ProB 2. Display version info about the ProB 2 Jupyter kernel, ProB 2, and the underlying ProB CLI.
:version :version
Display version info about the ProB CLI and ProB 2. Display version info about the ProB 2 Jupyter kernel, ProB 2, and the underlying ProB CLI.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` prob ``` prob
:version :version
``` ```
%% Output %% Output
ProB CLI: 1.9.3-nightly (50333f1779dcae2a9e6d1b2aa95a23678821f851) ProB 2 Jupyter kernel: 1.0.1-SNAPSHOT (2b75217bf8bef7737632efee1ebb1ddbd8cfefe6)
ProB 2: 4.0.0-SNAPSHOT (1d61b6ea7ef1b2e38a6b6045dbb0e81bcb6d8423) ProB 2: 3.10.0 (0ee5d5eea6894b2899690565dfc3d9042098ce89)
ProB CLI:
1.9.3-final (64afef0148d6ce70f2af5082e69269c950078133)
Last changed: Wed Feb 19 11:16:13 2020 +0100
Prolog: SICStus 4.5.1 (x86_64-darwin-17.7.0): Tue Apr 2 15:34:32 CEST 2019
......
package de.prob2.jupyter; package de.prob2.jupyter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -9,6 +13,7 @@ import java.util.Collections; ...@@ -9,6 +13,7 @@ import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -70,6 +75,24 @@ import org.slf4j.LoggerFactory; ...@@ -70,6 +75,24 @@ import org.slf4j.LoggerFactory;
@Singleton @Singleton
public final class ProBKernel extends BaseKernel { public final class ProBKernel extends BaseKernel {
/**
* Inner class for safe lazy loading of the build info.
*/
private static final class BuildInfo {
static final Properties buildInfo;
static {
buildInfo = new Properties();
try (final Reader reader = new InputStreamReader(
ProBKernel.class.getResourceAsStream("/de/prob2/jupyter/build.properties"),
StandardCharsets.UTF_8
)) {
buildInfo.load(reader);
} catch (final IOException e) {
throw new AssertionError("Failed to load build info", e);
}
}
}
private static final @NotNull Logger LOGGER = LoggerFactory.getLogger(ProBKernel.class); private static final @NotNull Logger LOGGER = LoggerFactory.getLogger(ProBKernel.class);
private static final @NotNull Pattern COMMAND_PATTERN = Pattern.compile("\\s*(\\:[^\\s]*)(?:\\h*(.*))?", Pattern.DOTALL); private static final @NotNull Pattern COMMAND_PATTERN = Pattern.compile("\\s*(\\:[^\\s]*)(?:\\h*(.*))?", Pattern.DOTALL);
...@@ -196,6 +219,18 @@ public final class ProBKernel extends BaseKernel { ...@@ -196,6 +219,18 @@ public final class ProBKernel extends BaseKernel {
this.currentMachineDirectory = Paths.get(""); this.currentMachineDirectory = Paths.get("");
} }
private static @NotNull Properties getBuildInfo() {
return ProBKernel.BuildInfo.buildInfo;
}
public static @NotNull String getVersion() {
return getBuildInfo().getProperty("version");
}
public static @NotNull String getCommit() {
return getBuildInfo().getProperty("commit");
}
public @NotNull Map<@NotNull String, @NotNull Command> getCommands() { public @NotNull Map<@NotNull String, @NotNull Command> getCommands() {
return Collections.unmodifiableMap(this.commands); return Collections.unmodifiableMap(this.commands);
} }
......
...@@ -5,6 +5,7 @@ import com.google.inject.Inject; ...@@ -5,6 +5,7 @@ import com.google.inject.Inject;
import de.prob.Main; import de.prob.Main;
import de.prob.animator.command.GetVersionCommand; import de.prob.animator.command.GetVersionCommand;
import de.prob.statespace.AnimationSelector; import de.prob.statespace.AnimationSelector;
import de.prob2.jupyter.ProBKernel;
import io.github.spencerpark.jupyter.kernel.ReplacementOptions; import io.github.spencerpark.jupyter.kernel.ReplacementOptions;
import io.github.spencerpark.jupyter.kernel.display.DisplayData; import io.github.spencerpark.jupyter.kernel.display.DisplayData;
...@@ -34,7 +35,7 @@ public final class VersionCommand implements Command { ...@@ -34,7 +35,7 @@ public final class VersionCommand implements Command {
@Override @Override
public @NotNull String getShortHelp() { public @NotNull String getShortHelp() {
return "Display version info about the ProB CLI and ProB 2."; return "Display version info about the ProB 2 Jupyter kernel, ProB 2, and the underlying ProB CLI.";
} }
@Override @Override
...@@ -44,9 +45,22 @@ public final class VersionCommand implements Command { ...@@ -44,9 +45,22 @@ public final class VersionCommand implements Command {
@Override @Override
public @NotNull DisplayData run(final @NotNull String argString) { public @NotNull DisplayData run(final @NotNull String argString) {
final StringBuilder sb = new StringBuilder("ProB 2 Jupyter kernel: ");
sb.append(ProBKernel.getVersion());
sb.append(" (");
sb.append(ProBKernel.getCommit());
sb.append(")\nProB 2: ");
sb.append(Main.getVersion());
sb.append(" (");
sb.append(Main.getGitSha());
sb.append(")\nProB CLI:");
final GetVersionCommand cmd = new GetVersionCommand(); final GetVersionCommand cmd = new GetVersionCommand();
this.animationSelector.getCurrentTrace().getStateSpace().execute(cmd); this.animationSelector.getCurrentTrace().getStateSpace().execute(cmd);
return new DisplayData(String.format("ProB CLI: %s\nProB 2: %s (%s)", cmd.getVersion(), Main.getVersion(), Main.getGitSha())); for (final String line : cmd.getVersionString().split("\\n")) {
sb.append("\n\t");
sb.append(line);
}
return new DisplayData(sb.toString());
} }
@Override @Override
......
# The values for these properties are generated during the build.
# See the configuration of the processResources task in build.gradle.
version=${version}
commit=${commit}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment